Results 1 to 8 of 8
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 ...
- 01-31-2008 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 4
grep/awk help, how do i make this shorter?
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
or i could use the awk command that franklin suggested, something like
awk '
while(stdin == FILE > 0 ) {
stdin[$1] = $1
}
}
!stdin[$1]{print}
' "datafile.txt"
edit: nvm franklin got it the same way
- 01-31-2008 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
show how your numbers.txt look like, and also describe how you want to final output to be
- 01-31-2008 #3Just Joined!
- Join Date
- Jan 2008
- Posts
- 4
numbers.txt have words not numbers sorry
like
---numbers.txt---
hi how are you
what are you doing
or am i sleeping
the zebra ate the lion
yes sir
a banana fell
------------------
So I Would want to remove the lines that start with or, the, a so in the above file, line 3,4,and 6 would be removed. Thanks
The rest of the file should remain unchanged
- 01-31-2008 #4Just Joined!
- Join Date
- Jan 2008
- Posts
- 1
first thing I would try about making this shorter was to only call grep once, and then use subexpression.
That is the easiest way to start something like
grep (-i -v ^the| -i -v ^or| -i -v ^a) instead of calling grep multiply times, and beyond this I cannot help - I know not so much myself yet....
But that is the more obvious way to go
- 01-31-2008 #5Just Joined!
- Join Date
- Jan 2008
- Posts
- 4
alright i made it shorter, and this works, but what do i do if i have a txt file that has more words i want to exclude? like -- and, if, you, etc etc
./new < numbers.txt | grep -i -v '^a \|^the \|^or ' | sort -f
looks like grep is not so good to make it for a list, so im going to work with the awk, seeing you can do actual programming in it
- 01-31-2008 #6Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
See the solution below.
Regards
- 01-31-2008 #7Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
The OP deleted his question, for clarity, this was the request:
Try this:
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
RegardsCode:./new < numbers.txt | awk ' BEGIN{while(getline < "datafile.txt" > 0 ) { arr[$1]=$1 } close("datafile.txt") } !arr[$1]{print} '
- 01-31-2008 #8Just Joined!
- Join Date
- Jan 2008
- Posts
- 4
cool, thanks frank i actually spend like 5 hours and finally got it working, and i check back here and you have almost same thing but better..what a waste of time lool, but i did learn alot

thanks


Reply With Quote