I have been using grep for removing lines of a particular pattern from a long file in the following way
grep -vf Exclude_Lines File1 > File2
But grep seems to have some problems because sometimes it does the job, sometimes it does not....I have seen AWK is more powerful..
Can the same thing be done by using AWK?
# print only lines which match regular expression (emulates "grep")
awk '/regex/'
# print only lines which do NOT match regex (emulates "grep -v")
awk '!/regex/'
# awk '!/(firstexp|secondexp)/' fileone > filetwo
sed
# print only lines which match regular expression (emulates "grep")
sed -n '/regexp/p' # method 1
sed '/regexp/!d' # method 2
# print only lines which do NOT match regexp (emulates "grep -v")
sed -n '/regexp/!p' # method 1, corresponds to above
sed '/regexp/d' # method 2, simpler syntax
Thanks IKON....... actually i just figured out what grep is doing.....its not the fault of grep
I have a file where 19224 lines are there with lines like (giving a snapshot)
1 1 1 2
2 2 2 3
3 3 3 4
In the file where I have mentioned all the patterns using which I need to remove selected lines containing these patterns, I have mentioned
77 78
in order to remove the line where the 3rd and 4th columns are 77 and 78.
The line which I wanted to remove looks like
81 5 77 78
But in the process, GREP is removing the following lines apart from the one (mentioned above) that I wanted to remove.
8373 9 7877 7878
8374 9 7877 7879
8375 9 7877 7880
Because its finding 77 and 78 next to each other according to my pattern, its removing these lines. Is there a better way to tackle this problem rather than mentioning the entire line as "81 5 77 78" in my pattern matching file?