[英]Bash: How to keep line if number in second column is greater than 3?
What is the best way to keep line if number in second column (separated by space) is greater than 3? 如果第二列中的数字(以空格分隔)大于3,则保持行的最佳方法是什么?
And I MUST NOT use awk or sed! 而且我绝对不能使用awk或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
使用while
循环:
while read -r i j k; do [ "$j" -gt 3 ] && echo "$i $j $k"; done <file.txt
Using grep
to filter out unwanted requirements 使用
grep
过滤掉不需要的需求
$ 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
使用while循环
while read line; do if [ $(echo $line|cut -d " " -f2) -gt 3 ]; then echo $line; fi; done < testfile.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.