Awk Command line commands

Useful command line commands

# Use specific separator for awk columns
awk -v OFS='\t' '{print $5, $1}'

# Add extry entry to each processed line
awk '{print $0, "extra entry"}'

# Conditional printing of lines of text (e.g print lines of myFile.txt if values in 5th columm are not ".")
awk '{ if ($5 != ".") { print } }' myFile.txt

# calc sum of difference two columns
cat Regions.bed | awk -F'\t' 'BEGIN{SUM=0}{ SUM+=$3-$2 }END{print SUM}'

cat twist_swift_GI.bed | awk '{for(i=$2;i<$3;i++) print $1"\t"i}' | wc -l

# standard replacement
sed -i "s/pattern/replacement/g" file_name


# esubstitute var with slashes
sed -i "s|$var|r_str|g" file_name


#from standard out
cat test | sed -e "s/$var/r_str|g"