LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Excluding a string in awk when printing (https://www.linuxquestions.org/questions/programming-9/excluding-a-string-in-awk-when-printing-539522/)

szahri 03-21-2007 11:27 PM

Excluding a string in awk when printing
 
Hi all,
Lets say I have a file that have 4 columns and 400 rows in it, and I want to print out all the rows and columns except the one with the entry 'Suzana' in it..how do I do it?

I'm not sure how to exclude the rows containing Suzana and printing out the rest using awk..can I use substr for this?

Thanks!

ghostdog74 03-22-2007 01:09 AM

Quote:

Originally Posted by szahri
Hi all,
Lets say I have a file that have 4 columns and 400 rows in it, and I want to print out all the rows and columns except the one with the entry 'Suzana' in it..how do I do it?

I'm not sure how to exclude the rows containing Suzana and printing out the rest using awk..can I use substr for this?

Thanks!

eg
Code:

awk '$0 !~ /Suzana/ { print }' file
why not just use grep
Code:

grep -v "Suzana" file

Tinkster 03-22-2007 02:00 AM

Quote:

Originally Posted by ghostdog74
eg
Code:

awk '$0 !~ /Suzana/ { print }' file

Too verbose :}
Code:

awk '!/Suzanna/' file

Cheers,
Tink


All times are GMT -5. The time now is 12:41 PM.