Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Mix text file

  1. #1
    Join Date
    Oct 2010
    Beans
    26

    Question Mix text file

    Hello everyone,

    I have 2 file .txt containing email addresses.
    The first txt file has email with domain.net like user1@domain.net
    The second has email with domain.com like user1@domain.com


    Now i want to find and wrap the corresponding username for .net and .com in format:

    user1@domain.net : user1@domain.com

    and save into a file.

    Thanks in advanced

  2. #2
    Join Date
    Oct 2010
    Beans
    26

    Re: Mix text file

    Please help me.

  3. #3
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,277
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Mix text file

    do these files match on a per line basis or are they unsorted? are there addresses which don't have their 2nd version in the other file?
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  4. #4
    Join Date
    Oct 2010
    Beans
    26

    Question Re: Mix text file

    Quote Originally Posted by Vaphell View Post
    do these files match on a per line basis or are they unsorted? are there addresses which don't have their 2nd version in the other file?
    Not match on per line. But i use uniq to wrap all matching emails to on file also. Is there any way to bring them to that format?

    in new txt file there will be

    user1@domain.net
    user1@domain.com
    user2@domain.net
    uesr2@domain.com

    and so on.

  5. #5
    Join Date
    Apr 2012
    Beans
    5,308

    Re: Mix text file

    I'm still finding it a bit difficult to understand exactly what you want to do - remember that the better you define the problem, the easier it is to solve

    If your files look like this:

    Code:
    $ cat com.txt
    user1@abcd.com
    user2@efgh.com
    user3@abcd.com
    $
    $ cat net.txt
    user5@abcd.net
    user2@efgh.net
    user1@abcd.net
    $
    then you could do something like

    - read entries one at a time from one of the files
    - search the other file for a 'match'
    - if successful, output the 2 entries

    e.g. using the bash shell + 'grep'

    Code:
    $ while read -r netaddr; do comaddr=$(grep -m1 -o "${netaddr%.net}.com" com.txt); if [ ! -z "$comaddr" ]; then echo "$netaddr" : "$comaddr"; fi; done < net.txt
    user2@efgh.net : user2@efgh.com
    user1@abcd.net : user1@abcd.com

  6. #6
    Join Date
    Oct 2010
    Beans
    26

    Re: Mix text file

    Sorry for my bad explains.
    now i would like to read 2 text files and wrap the matching username in format like

    aadrian@abc.net : aadrian@abc.com
    Thanks
    Last edited by hunterlove22; February 8th, 2013 at 05:00 PM.

  7. #7
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,909
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Mix text file

    Code:
    for i in $(cut -d "@" -f 1 com.txt); do netvar="$(grep $i net.txt)"; comvar="$(grep $i net.txt)"; echo "$netvar : $comvar" ; done;
    AND YOU GET THESE:
    TO OUTPUT TO A FILE(united.txt) DO :
    for i in $(cut -d "@" -f 1 com.txt); do netvar="$(grep $i net.txt)"; comvar="$(grep $i net.txt)"; echo "$netvar : $comvar" >> united.txt; done;
    there is also a little problem, when there is no match you get an empty line with ":" ate the beggining. you can fix that with "uniq united.txt > united2.txt" and you get only 1 blank line containing it.
    Last edited by fdrake; February 8th, 2013 at 01:42 AM.

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

  8. #8
    Join Date
    Oct 2010
    Beans
    26

    Re: Mix text file

    Quote Originally Posted by fdrake View Post
    Code:
    for i in $(cut -d "@" -f 1 com.txt); do netvar="$(grep $i net.txt)"; comvar="$(grep $i net.txt)"; echo "$netvar : $comvar" ; done;
    AND YOU GET THESE:


    TO OUTPUT TO A FILE(united.txt) DO :


    there is also a little problem, when there is no match you get an empty line with ":" ate the beggining. you can fix that with "uniq united.txt > united2.txt" and you get only 1 blank line containing it.
    Thanks for your awesome reply. Btw, i need the format:

    aadrian@abc.net : aadrian@abc.com
    Last edited by hunterlove22; February 8th, 2013 at 05:00 PM.

  9. #9
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,909
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Mix text file

    Quote Originally Posted by hunterlove22 View Post
    Thanks for your awesome reply. Btw, i need the format:

    aadrian@pfaonline.net : aadrian@pfaonline.com
    my bad I misstyped the name file(change one of the net.txt to com.txt): it should have been:
    Code:
    for i in $(cut -d "@" -f 1 com.txt); do netvar="$(grep $i net.txt)"; comvar="$(grep $i com.txt)"; echo "$netvar : $comvar" ; done;

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

  10. #10
    Join Date
    Oct 2005
    Location
    Al Ain
    Beans
    7,909

    Re: Mix text file

    Load the files into a spreadsheet like gnumeric. you can go crazy in there and then save as csv

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •