![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| nawk-how count the number of occurances of a pattern, when don't know the pattern | cyber111 | Shell Programming and Scripting | 2 | 05-11-2008 04:00 AM |
| Delete a block of text delimited by blank lines when pattern is found | gleu | Shell Programming and Scripting | 17 | 12-16-2007 11:30 PM |
| getting the stanza names if the pattern found | vijaya2006 | Shell Programming and Scripting | 4 | 09-25-2007 10:03 AM |
| Search file for pattern and grab some lines before pattern | frustrated1 | Shell Programming and Scripting | 2 | 12-22-2005 03:41 PM |
| "pattern not found" ??? | maybenexttime62 | UNIX for Dummies Questions & Answers | 5 | 10-26-2002 03:06 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Pattern not found : AWK , help
Hi All, My file : Code:
$ cat my.txt
AA:22:note:AA
BB:AA:help:XX
CC:14:AA:CC
ZZ:AA:hello:AA
A) <searching "AA" as 2nd field in all lines of my.txt >
$ awk -F ":" '{ if ($2 ~ /AA/) print "found in line - " NR; else print "Not found"}' my.txt
Not found
found in line - 2
Not found
found in line - 4
B) <"XX" is not present as 2nd field in my.txt>
$ awk -F ":" '{ if ($2 ~ /XX/) print "found in line - " NR; else print "Not found"}' my.txt
Not found
Not found
Not found
Not found
How can I output this: - A) output should be: Code:
found in line - 2 found in line - 4 ** I can do a grep -v "Not found" in the awk output to remove the "Not found"(s), but I want to do it with awk without doing "pipe" - B) output should be: Code:
Not found ** i.e. a single "Not found" if pattern is not present as 2nd field in any of the lines. HTH, jkl_jkl |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|