LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-21-2007, 11:27 PM   #1
szahri
LQ Newbie
 
Registered: Mar 2005
Posts: 11

Rep: Reputation: 0
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!
 
Old 03-22-2007, 01:09 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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
 
Old 03-22-2007, 02:00 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally Posted by ghostdog74
eg
Code:
awk '$0 !~ /Suzana/ { print }' file
Too verbose :}
Code:
awk '!/Suzanna/' file

Cheers,
Tink

Last edited by Tinkster; 03-22-2007 at 02:01 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
awk escape character for colon in string quadmore Programming 2 02-27-2007 04:56 PM
awk column printing schneidz Programming 7 09-29-2005 06:14 AM
[Bash] Concatenate string using awk senorsnor Programming 7 05-05-2005 12:38 AM
Weird string printing problem (in C) Keffin Programming 4 02-05-2004 03:09 AM
string concatenation in AWK xanthium Programming 1 04-22-2002 04:41 AM


All times are GMT -5. The time now is 10:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration