One liner if-else in awk
— Kaushal ModiTiny snippets showing if/else use in awk
..
echo abc:def | awk -F: '{ if ( $2 ) {print $2} else {print} }'
Prints def
.
echo abc | awk -F: '{ if ( $2 ) {print $2} else {print} }'
Prints abc
.
Tiny snippets showing if/else use in awk
..
echo abc:def | awk -F: '{ if ( $2 ) {print $2} else {print} }'
Prints def
.
echo abc | awk -F: '{ if ( $2 ) {print $2} else {print} }'
Prints abc
.