Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dumb unix question...sorry ahead of time

Status
Not open for further replies.

sasuser2006

Technical User
May 8, 2006
32
US
I am wanting to grep the contents of fileA in fileB...so if anything in fileB exist in fileA i want to write it out to fileC but i can't remember how to grep a file instead of a string.

I know this isn't right but i can't get it to work anyway...

grep fileA fileB > fileC

or

grep fileA < fileB > fileC

Thanks in advance for your help.
 
If your matching lines are identical, you could use the "comm" command.

$ comm -12 fileA fileB >fileC You would get better results if you were to sort fileA and fileB first. Unless, of course, you need to maintain the order of the lines.



"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Would the comm command work for the given data?

fileA contents are:

12345ABC90123456ABC
234519YJF3094239DEF
10329480RST83920GHI

fileB contents are:

12345ABC90123456
123908234BCD3402
4320FGR028430920

I want to know if the 16 byte alpha-numeric field in fileB exists in fileA and if it does write that out to output1 and if it doesn't write it out to output2. Thanks for the advice already and any future advice given.

 
You can write a quick korn shell script using arrays and loop through each line in each file to check for the existence of the string and write it out to whatever file you choose.

Arrays are set using: set -A arrayName $(command)
 
Thanks for the advice...know anywhere good that can walk me through writing a korn shell...I haven't ever written one.
 
Some greps support -f, e.g. grep -f fileA fileB > fileC. Which operating system/version of grep are you using?

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top