The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to rewrite a line in a file c0384 Shell Programming and Scripting 21 05-21-2007 11:06 PM
How do I rewrite to use a while instead of find? goodmis Shell Programming and Scripting 4 02-06-2007 11:20 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-24-2006 09:20 PM
rewrite the same info in 3 different files strok Shell Programming and Scripting 6 03-29-2003 10:50 AM
Apache Rewrite help! hassan2 UNIX for Advanced & Expert Users 1 11-11-2002 10:35 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
Delete

Thanks , franklin you method worked, i knew i had to use a while loop and getline in there just didnt know the proper order

Hi everyone, im trying to make the following command line shorter by introducing a script that join up all the grep commands

./new1a < numbers.txt | grep -i -v '^a ' | grep -i -v '^the ' | grep -i -v '^or ' | sort -f

How would I go about merging all the greps into a scripe and putting all the words that should be excluded into a data file

Last edited by weezybaby; 01-31-2008 at 03:44 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 01-31-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,199
With awk you can do something like this:

Code:
awk '
FNR==NR{arr[$1]=$1;next}
!arr[$1]{print}
' "datafile.txt" "numbers.txt"
Regards
Reply With Quote
  #3  
Old 01-31-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 286
Code:
#  cat numbers.txt

hi how are you
what are you doing
or am i sleeping
the zebra ate the lion
yes sir
a banana fell

#  cat exclude.file
^a
^the
^or



#   /usr/xpg4/bin/grep -v -f exclude.file numbers.txt

hi how are you
what are you doing
yes sir
Reply With Quote
  #4  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
alright ll give it a try

Last edited by weezybaby; 01-31-2008 at 03:33 PM.
Reply With Quote
  #5  
Old 01-31-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,199
The OP deleted his question, for clarity, this was the request:
Quote:
Output of his command "./new < numbers.txt ":

hi how are you
what are you doing
or am i sleeping
the zebra ate the lion
yes sir
a banana fell

File datafile.txt:

a
the
or

Desired output:

hi how are you
what are you doing
yes sir

Try this:

Code:
./new < numbers.txt | awk '
  BEGIN{while(getline < "datafile.txt" > 0 ) {
    arr[$1]=$1
  }
  close("datafile.txt")
}
!arr[$1]{print}
'
Regards

Last edited by Franklin52; 02-01-2008 at 12:46 AM.
Reply With Quote
  #6  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
Thanks I almost got the same thing, just had some syntax issue that you have corrected . Thank you once again
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0