1753893 Members
7777 Online
108809 Solutions
New Discussion юеВ

text file manipulation

 
SOLVED
Go to solution
navin
Super Advisor

text file manipulation

Hello i have a text file A which has a user info .So this file contains 6000 entries for 6000 users.Each entry has a field for phone number of the user . There will be multiple entry for some users as well.

Now i have a file B with pager numbers for users lised in file A. I have to replace the phone numbers with corresponding pagers numbers.

How can i implement this .Please help . I really appreciated all your help

Thanks
Learning ...
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: text file manipulation

Hi Navin:

Have a look at 'join'. See the manpages for details.

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: text file manipulation

It might be easier to provide a useful answer
if you would exhibit a few lines from each
file, and what you would like to see in the
resulting file.
navin
Super Advisor

Re: text file manipulation

Here is an example entry from file A

marks:8975:Mark:Sam:mark.sam@urs.com:781-829-0010:active::
marks1:8975:Mark:Sam:mark.sam@urs.com:781-829-0010:active:user name changed for marks:
stevew:8978:Steve:watt:steve.watt@urs.com:480-888-2342:active:


Here is an example entry from file B

marks1 260800121
stevew 670234123

Trying to replace phone numbers in file A with pager number in file B for each user

Thanks

Learning ...
Sandman!
Honored Contributor

Re: text file manipulation

Assumes that fileA and fileB are sorted and the field separator for both is ":"

# cat fileA
marks:8975:Mark:Sam:mark.sam@urs.com:781-829-0010:active::
marks1:8975:Mark:Sam:mark.sam@urs.com:781-829-0010:active:user name changed for marks:
stevew:8978:Steve:watt:steve.watt@urs.com:480-888-2342:active:

# sed 's/ /:/g' fileB | sort -t: -k1,1 > fileB
# cat fileB
marks1:260800121
stevew:670234123

# join -t: -j1 1 -o 1.1 1.2 1.3 1.4 1.5 2.2 1.7 1.8 fileA fileB