Samy Samy - 1 month ago 14
Bash Question

Shell script: grep a table of values from a file

I have a result file that looks like this:

data data data data data...
data data data data data...
data data data data data...

#0
data data is 2

#1
data data is 2

testing data ( )

n m
256 729.44
352 1555.07
448 2649.68

#2
data data is 2

#3
data data is 2


I need to grep only the table that will always have 2 columns of n and m(it can get very long). So the output should be:

n m
256 729.44
352 1555.07
448 2649.68


I've tried using awk and grep but I can only get one line not the whole table. Any help would be appreciated it.

Answer

Using AWK you would print all lines where the Number of Fields equals to 2:

awk 'NF == 2' data.txt