Reputation: 405
What is the best way to keep line if number in second column (separated by space) is greater than 3?
And I MUST NOT use awk or sed! -.-
Input:
2 2 asd 132ds
1 4 sdf 234sd
1 3 gfd 654gh
1 1 rtz 543jh
1 10 uio 654iu
Output:
1 4 sdf 234sd
1 10 uio 654iu
Upvotes: 2
Views: 655
Reputation: 77135
Using grep
to filter out unwanted requirements
$ cat file
2 2 asd 132ds
1 4 sdf 234sd
1 3 gfd 654gh
1 1 rtz 543jh
1 10 uio 654iu
$ egrep -v '^[^.]+ [1-3] ' file
1 4 sdf 234sd
1 10 uio 654iu
Upvotes: 2
Reputation: 11
Using while loop
while read line; do if [ $(echo $line|cut -d " " -f2) -gt 3 ]; then echo $line; fi; done < testfile.txt
Upvotes: 1
Reputation: 42087
Use a while
loop:
while read -r i j k; do [ "$j" -gt 3 ] && echo "$i $j $k"; done <file.txt
Upvotes: 3