Here is a test.txt file
sometext
someothertext
...
lol
74
hhhhh
lol
789AA
I want a bash command that only displays:
74
For this I have tried:
awk '$0 == "lol" {i=1;next};i && i++ <= 1' test.txt
which for now displays
74
789AA
So, how can I augment this command so that it only displays a line that only contains a number (74) ?
Thanks
>Solution :
This awk should work for you:
awk 'p == "lol" && $0+0 == $0; {p = $0}' file
74
$0+0 == $0 will return true only when $0 contains a number only.