LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 11-04-2011, 09:24 AM   #1
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 737

Rep: Reputation: 78
Awk conditional how-to


i have need a line in my awk script that basically says "if this or this or this or this, then do nothing"

right now it checks for empty line
if ( NF == 0 ) {}

but i need to add some OR's in there, need to check if $0 contains a pattern.

can i do this
if ( NF == 0 || $0 ~ /foo/ || $0 ~ /abc123/ ) {}

Last edited by Linux_Kidd; 11-04-2011 at 09:31 AM.
 
Old 11-04-2011, 09:35 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
http://www.gnu.org/software/gawk/man...ode/index.html
 
0 members found this post helpful.
Old 11-04-2011, 09:51 AM   #3
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 737

Original Poster
Rep: Reputation: 78
Quote:
Originally Posted by grail View Post

well, i didnt want to go learn everything about awk (just not enough time right now), hence why i posted. i tested my bloated example and it works fine. then i did regex modification

if ( NF == 0 || $0 ~ /(pattern1)|(pattern2)|(pattern3)/ ) {}


thnx.

Last edited by Linux_Kidd; 11-04-2011 at 10:07 AM.
 
Old 11-04-2011, 10:46 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
You will find the site is broken up very well and under informative headings. I would suggest about 2 clicks from the top level could have explained how to OR
 
Old 11-04-2011, 11:21 AM   #5
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 737

Original Poster
Rep: Reputation: 78
Quote:
Originally Posted by grail View Post
You will find the site is broken up very well and under informative headings. I would suggest about 2 clicks from the top level could have explained how to OR
its a great guide. thnx.
 
  


Reply



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
conditional greping ut0ugh1 Programming 7 10-27-2011 02:12 PM
[SOLVED] conditional substitution sharky Programming 3 08-18-2011 10:54 AM
awk conditional statmt problem raghu123 Programming 1 03-25-2009 03:10 PM
How to use conditional #define? kranti Programming 3 09-20-2006 09:06 AM
Conditional Compilation oulevon Programming 3 02-26-2006 08:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:13 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration