Code_rocks Code_rocks - 3 months ago 6
Bash Question

Remove the line in the file Which has only number in shell script

I have one file which contain sequence of number in every line. I want to remove the line which has only number

I tried (to no avail):

$ cat -n input_file > output_file


My file contain

1 name
2
3 Age
4
5 state
6 city


i want the output as

1 name
3 Age
5 state
6 city

Answer

A simple awk formula would do:

cat input_file | awk ' ($2 != "") { print $N } '

Edit: Cleaner way from Tom's comment

awk ' ($2 != "") { print $0 } ' input_file
Comments