1
$ cat file.txt | head -n10
icmp_seq=1 ttl=128 time=50.0 ms
icmp_seq=2 ttl=128 time=51.9 ms
icmp_seq=3 ttl=128 time=50.9 ms
icmp_seq=4 ttl=128 time=49.9 ms
$ cat file.txt | grep -v 'time=5 . ms' | head -n 5
icmp_seq=1 ttl=128 time=50.0 ms
icmp_seq=2 ttl=128 time=51.9 ms
icmp_seq=3 ttl=128 time=50.9 ms
icmp_seq=4 ttl=128 time=49.9 ms

I want it like this with all lines with "time=5X.XXms" ​​excluded:

$ cat file.txt | grep -v "time=5 . ms" | head -n 5
icmp_seq=4 ttl=128 time=49.9 ms
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Gustavo
  • 15
  • 6

1 Answers1

1

I think you can use [0-9] for X, which would give the following regular expression:

time=5[0-9].[0-9][0-9] ms

So you get following command:

cat file.txt | grep -v "time=5[0-9].[0-9][0-9] ms" | head -n 5
Dominique
  • 16,450
  • 15
  • 56
  • 112
  • 1
    should be just one `[0-9]` after the `.` character.. can also use `grep -m5 -v 'time=5[0-9].[0-9] ms' file.txt` to do it in one command instead of three – Sundeep Feb 07 '20 at 14:19
  • Perfect! I just added the space: cat file.txt | grep -v 'time=5[0-9].[0-9] \ms' Thanks – Gustavo Feb 07 '20 at 14:19
  • 1
    Note that `.` will match any character unless quoted. – stark Feb 07 '20 at 15:03
  • The [`cat` is useless](/questions/11710552/useless-use-of-cat) and the `head` can be avoided with `grep -m 5` – tripleee Feb 18 '20 at 13:27