Some helpful SED and AWK scripts

I regularly use some simple SED and AWK scripts to simplify life, but I tend to forget the specifics of their syntax, and have to start googling over and over and over in order to find something useful along the lines I want to have. SO here's a collection of stuff that I can easily copy/paste to my Terminal. It may not always be the best way to go about stuff, it simply works, so that's that. Don't complain or contact me with better solutions as I won't really care :)

Split a line into multiple lines

The following AWK oneliner splits a line into multiple lines, for a specific separator (":" in this case)

$echo "text:text:text" | awk -v RS=":" 'length()==0{next}{print$0}' text text text

Combining above

For a tab separated input with 3 columns, select those rows where the 3rd column is not "0".

awk 'BEGIN {FS="\t"} {OFS="\t"} {if($3!="0")print$1,$2,$3;}'

sed '1d' file

Count the number of columns in a file

awk 'BEGIN {FS="\t"} ; END{print NF}' file