Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
Highlighted
maliaka
Advisor

Re: Awk field seperator

closed