2

I'm having a file which contains following data

1. verification: 10 passed 0 failed
2. verification: 10 passed 0 failed
3. verification: 10 passed 1 failed
4. verification: 10 passed 3 failed
5. verification: 10 passed 0 failed

I want to know the line numbers of 3 and 4.

Raphael Ahrens
  • 9,701
  • 5
  • 37
  • 52
Chinna
  • 123
  • 1
  • 4

3 Answers3

2

Assuming the file is called in.txt, then:-

awk '$5>0 {print $0; }' in.txt

will give you:-

3. verification: 10 passed 1 failed
4. verification: 10 passed 3 failed

I've made the assumption the the line numbers (1-5) is part of the file. If it isn't change the $5 to $4.

If the line number is part of the file and you want to just print it without the dot:-

awk '$5>0 {sub(/\./,"",$1); print $1 }' in.txt

which gives:-

3
4
garethTheRed
  • 33,289
  • 4
  • 92
  • 101
1

With GNU grep, you can use lookbehind:

$ grep -P '(?<!0) failed' file 
3. verification: 10 passed 1 failed
4. verification: 10 passed 3 failed

Or a shorter version of awk:

$ awk '$5 > 0' file
cuonglm
  • 150,973
  • 38
  • 327
  • 406
0

Please note that i'm not printint real numbers, but the first number in the line until the dot.

With sed:

 cat inputfile.txt | sed  '/ 0 failed$/d ; s/\..*//'

With grep and sed:

 cat inputfile.txt | grep -v ' 0 failed$' | sed 's/\..*//'

Output:

3
4
LatinSuD
  • 1,401
  • 9
  • 8