The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep commands in loop karthikn7974 Shell Programming and Scripting 0 04-28-2008 09:16 AM
while loop inside while loop panknil Shell Programming and Scripting 0 01-07-2008 12:49 PM
grep and awk showing filename in loop sjohns6 Shell Programming and Scripting 5 05-24-2007 08:59 AM
grep in a loop gundu Shell Programming and Scripting 7 03-28-2005 04:59 PM
how to get the similar function in while loop or for loop trynew Shell Programming and Scripting 3 06-17-2002 11:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-25-2007
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
Red face grep -v while loop

alist contain:
a
b
c
d
e

blist contain:
a
b
c

the code:

#!/usr/bin/ksh
cat blist | while read line
do
grep -V "$line" alist > data
done

I expect to get

d
e

for my result but I don't. What is wrong?
  #2 (permalink)  
Old 01-25-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Quote:
Originally Posted by bobo
alist contain:
a
b
c
d
e

blist contain:
a
b
c

the code:

#!/usr/bin/ksh
cat blist | while read line
do
grep -V "$line" alist > data
done

I expect to get

d
e

for my result but I don't. What is wrong?
I would expect you output to be:
b
c
d
e
f
a
c
d
e
f
a
b
d
e

and have no Idea why you are doing something so convoluted, since you appear to be attempting to replicate the behaviour of fgrep -v (or grep -vf)
  #3 (permalink)  
Old 01-25-2007
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
Unhappy Please advise!

What I try to do is to get the different between alist and blist; in this case the result should be:

d
e

My alist is unknown list of data and so is blist. Let's say my alist contains:

e
b
c
a
d

and my blist contains:

c
a
b


Using the code that I have:

#!/usr/bin/ksh
cat blist | while read line
do
grep -V "$line" alist > data
done

What do I have to do to have a data file that contain:

e
d

Please advise! I tried "diff" it is not worked!
  #4 (permalink)  
Old 01-25-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
maybe you have a typo?? its supposed to be grep -v with small 'v', not 'V' ??
  #5 (permalink)  
Old 01-26-2007
milhan milhan is offline
Registered User
  
 

Join Date: Oct 2002
Location: /home
Posts: 133
Quote:
Originally Posted by bobo
Using the code that I have:
Code:
#!/usr/bin/ksh
cat blist | while read line
do
  grep -V "$line" alist > data
done
What do I have to do to have a data file that contain:

e
d

Please advise! I tried "diff" it is not worked!
Try this:

Code:
#!/usr/bin/ksh

# mydiff: gets the diff of two files and writes
# the difference to a third file.

cp alist data

cat blist |
while read line
do
  grep -v "$line" data > /tmp/data
  mv /tmp/data data
done

# end mydiff
  #6 (permalink)  
Old 01-26-2007
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
Thumbs up Mechanicly clever!

It works! Thanks! Are there other ways??? any else?
thanks!
  #7 (permalink)  
Old 01-26-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by bobo
It works! Thanks! Are there other ways??? any else?
thanks!
Code:
comm -3 file1 file2
Sort the files and then use the above command
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0