A Scripter's Notes

Emacs, scripting and anything text oriented.

One liner if-else in awk

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.

Comments

comments powered by Disqus