I have file abc.txt which has data like -
abc pqr testing, xyz=a432j42jjk4, key=124
abc pqr testing, xyz=jkl234j54nn, key=567
abc pqr testing, xyz=2395hdshkw4, key=3232
abc pqr testing, xyz=abc424729hh, key=7676
abc pqr testing, xyz=70700ghgh99, key=12342
I am searching text "xyz" using awk like -
awk -F"xyz=" '{print $2}' abc.txt | awk '{print $1}'
which gives me output with new lines in it -
a432j42jjk4,
jkl234j54nn,
2395hdshkw4,
abc424729hh,
70700ghgh99,
I am looking for shortcut or trick in awk where I can get output at the same time remove newlines from it.
NF {print $2}orNF {print $1}or both in your case. Placing NF makes sure that only non-blank lines/records are processed by the rule.