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 > 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 and shell scripting languages 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-22-2007 02:06 AM
How do I rewrite to use a while instead of find? goodmis Shell Programming and Scripting 4 02-06-2007 02:20 PM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 12:20 AM
rewrite the same info in 3 different files strok Shell Programming and Scripting 6 03-29-2003 01:50 PM
Apache Rewrite help! hassan2 UNIX for Advanced & Expert Users 1 11-11-2002 01:35 PM

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-31-2008
weezybaby weezybaby is offline
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 06:44 PM..
  #2 (permalink)  
Old 01-31-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
With awk you can do something like this:

Code:
awk '
FNR==NR{arr[$1]=$1;next}
!arr[$1]{print}
' "datafile.txt" "numbers.txt"
Regards
  #3 (permalink)  
Old 01-31-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
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
  #4 (permalink)  
Old 01-31-2008
weezybaby weezybaby is offline
Registered User
  
 

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

Last edited by weezybaby; 01-31-2008 at 06:33 PM..
  #5 (permalink)  
Old 01-31-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
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 03:46 AM..
  #6 (permalink)  
Old 01-31-2008
weezybaby weezybaby is offline
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
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 01:49 PM.


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