Re: Awk field seperator (192 Views)
Honored Contributor
Posts: 6,593
Registered: ‎05-19-2003
Message 26 of 29 (192 Views)

Re: Awk field seperator

Are these questions bulding up on one another? Does this new double match need to occur on the first line, or any line?
If it could be any line, then you need to read on until match or the END. If the END is reached, return other status:

awk '($1 ~ /^[0-9]+$/ && ($2 ~ /^[a-zA-Z0-9]+$/) {print; exit 0} END {exit 1}' tmp.txt

It's time to read that awk man page or book my friend!



Honored Contributor
Posts: 1,575
Registered: ‎02-10-2003
Message 27 of 29 (192 Views)

Re: Awk field seperator


to clarify the difference of Hein's solution to mine.

My solution aborts at the first line NOT containing twu fields, where the first consists of digits only.

Hein's solution terminates at the first correct entry with status 0; the return value is 1 when not a single correct field was found.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Honored Contributor
Posts: 2,220
Registered: ‎01-13-2005
Message 28 of 29 (192 Views)

Re: Awk field seperator

Not sure if i understand your requirement but based on your posts try the awk construct below:

# awk '/hell/ && !/awk/ {print (($3=="")?0:$3);exit}' file

Posts: 25
Registered: ‎01-07-2007
Message 29 of 29 (192 Views)

Re: Awk field seperator

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.