Wednesday, September 29, 2010

file manipulation

1) output total number of input file
awk 'END {print NR}' input_file

2) output #3 line Number of Field(NF)
awk 'NR==3 {print NF}' input_file

3) output lines that contains "INFO"
awk '/INFO/ {print}' input_file
less input_file | grep INFO

4) output lines that doesn't contain "INFO"
awk '!/INFO/ {print}' input_file
less input_file | grep -v INFO

5) output the second colum
awk -F "delimter" '{print $2}' input_file
cut -d "delimiter" -f2 input_file

6) output the first and the third colum
awk -F "delimter" '{print $1 $3}' input_file
cut -d "delimiter" -f1,3 input_file

No comments: