Jotne
1
Is there other way then this only solution I have found to print lines with numbers only?
file.txt
one
two
three
3
four
five
5tt
6gfjdfgdf
9
66
six
0
seven
7
eight
546546
gffdg445gfg
fd644
0112
awk '{n=$1/1; if(n==$1)print}' file.txt
3
9
66
0
7
546546
0112
$ sed -n "/^[0-9]\+$/ p" file.txt
3
9
66
0
7
546546
0112
Jotne
3
Thanks
From you input I see that this works on awk
awk '/^[0-9]+$/' file.txt
Yes, that would work perfectly.
Just bear in mind that a line would not be selected if there is so much as single space at the beginning or the end. An alternative would be:
awk 'NF==1 && $1~/^[0-9]+$/' file
In that case, if blanks allowed:
$ awk '/^ *[0-9]+ *$/' file.txt
3
9
66
0
7
546546
0112
Yes, but the then it would be better to use
awk '/^[ \t]*[0-9]+[ \t]*$/' file
Jotne
8
awk '{$1=$1} /^[0-9]+$/' file
I space and tabs are allowed, i found this better, since it also clean to output.