1828328 Members
3433 Online
109976 Solutions
New Discussion

Re: Awk field seperator

 
SOLVED
Go to solution
Hein van den Heuvel
Honored Contributor

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!

hth,

Hein

Peter Nikitka
Honored Contributor

Re: Awk field seperator

Hi,

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"
Sandman!
Honored Contributor

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

~cheers
maliaka
Advisor

Re: Awk field seperator

closed