Computing.Net > Forums > Solaris > grep file for key in loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

grep file for key in loop

Reply to Message Icon

Name: ReubenK
Date: December 19, 2003 at 07:43:12 Pacific
OS: Solaris
CPU/Ram: not known
Comment:

I have two text files f1.txt and f2.txt, each one has more than two millians of lines of text. I want to read each line in file f1.txt and grep for that in file f2.txt and if not matching then put the unmatched line in to another file f3.txt.

I tried the following way but getting errors, I appriciate if any one can put some input on this.

Thanks
Reuben


while read line
do
if [ 'grep ${line} f2.txt' -lt 0 ] ; then
echo ${line}
fi

done < f1.txt > f3.txt



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: December 19, 2003 at 09:59:02 Pacific
Reply:

Hi:

You're main problem was your choice of command substitution marks. If using Bourne it's ` not '

I'm using ksh:

#!/bin/ksh

while read line
do
if [[ $(grep -c ${line} f2.txt) == 0 ]] ; then
echo ${line}
fi

done < f1.txt > f3.txt
# end script

You probably know, this is going to take some time with millions of records.

Regards,


Nails


0

Response Number 2
Name: ReubenK
Date: December 24, 2003 at 07:32:06 Pacific
Reply:

Nails

Thank you so much, it is working fine.

Reuben


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Solaris Forum Home


Sponsored links

Ads by Google


Results for: grep file for key in loop

Solairs output file manipulation www.computing.net/answers/solaris/solairs-output-file-manipulation/5011.html

installation problem in everybuddy??? www.computing.net/answers/solaris/installation-problem-in-everybuddy/1768.html

SysRq key in solaris www.computing.net/answers/solaris/sysrq-key-in-solaris/1427.html