Gustavo
Gustavo

Reputation: 35

Linux command GREP - Exact value with space

$ 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

Upvotes: 1

Views: 114

Answers (1)

Dominique
Dominique

Reputation: 17471

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

Upvotes: 1

Related Questions