[英]How to extract a field which has value greater than a number using AWK or SED
[英]how to find the replace the digit which is greater than 100 using sed?
如何使用sed使用通配符? 我要搜索并替换大于100的“第7列”,将其替换为“ 100”
输入:
$ cat /tmp/test.in
Mon Sep 14 12:48:04 IST 2015, 1
Mon Sep 14 12:50:04 IST 2015, 110
预期产量:
Mon Sep 14 12:48:04 IST 2015, 1
Mon Sep 14 12:50:04 IST 2015, 100
$ sed -i's /,\\ 1。* /,100 / g'/tmp/test.in
Mon Sep 14 12:48:04 IST 2015, 100
Mon Sep 14 12:50:04 IST 2015, 100
但您会在第7列看到何时将数字“ 1”替换为“ 100”。 如何实现呢?
提前致谢
awk '$7>100{$7=100}7' file
sed不太适合进行匹配计算/比较,请改用awk。
sed -e '/,[[:blank:]]*[1-9]\{1,2\}$/b' -e '/,[[:blank:]]*100$/b' -e 's/,[^,]*$/, 100/' YourFile
[root@test /tmp]$ sed 's/,\ 1..*/, 100/g' a
Mon Sep 14 12:48:04 IST 2015, 1
Mon Sep 14 12:50:04 IST 2015, 100
这可能对您有用(GNU sed):
sed -r 's/ \S\S\S+$/ 100/' file
由于最后一个字段仅包含一个整数,因此任何具有3个或更多数字的数字都可以替换为100
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.