BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Awk field seperator

Go to Solution
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!



Honored Contributor

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

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


Re: Awk field seperator