1
Is that possible to precise conditions in "if" statement? Let's take an example from my previous post (by the way, "k" variable is tricky, thanks terdon;)) and say that I'm looking for $i which starts from two capital letter, after that we have 2 digits, other letters/digits are not important and lenght of the word which I'm looking for is not constant (in example: AB12asdf or HR56Ame4).
awk '{k=0; for (i=1;i<=NF;i++){
if ($i=="ABC"){print $(i-2); k++} } if(k==0){print "No ABC in line",NR} }' file.txt
Thanks,
lucas
You can be as precise as the condition you write matches on.
/^[[:upper:]][[:upper:]][[:digit:]][[:digit:]]/
will match two upper-case letters followed by two digits. – Etan Reisner – 2013-11-26T19:47:08.030