awk 比较问题
时间:2011-06-03
来源:互联网
# df -h|grep "/dev/ram0"|awk '{
temp=$4;
if(temp ~ /G$/) print 1;
else if(temp ~ /M$/) {
sub("M","",temp);print temp;
if(temp > "300") print 1;else print 0;
}
}'
1020
0
# df -h|grep "/dev/ram0"|awk '{
temp=$4;
if(temp ~ /G$/) print 1;
else if(temp ~ /M$/) {
sub("M","",temp);print temp;
if(temp > 300) print 1;else print 0;
}
}'
1020
0
# df -h|grep "/dev/ram0"|awk '{
temp=$4;
if(temp ~ /G$/) print 1;
else if(temp ~ /M$/) {
sub("M","",temp);print "#"temp"#";
if(temp > 300) print 1;else print 0;
}
}'
#1020#
0
神马问题,1020不大于300 ?
temp=$4;
if(temp ~ /G$/) print 1;
else if(temp ~ /M$/) {
sub("M","",temp);print temp;
if(temp > "300") print 1;else print 0;
}
}'
1020
0
# df -h|grep "/dev/ram0"|awk '{
temp=$4;
if(temp ~ /G$/) print 1;
else if(temp ~ /M$/) {
sub("M","",temp);print temp;
if(temp > 300) print 1;else print 0;
}
}'
1020
0
# df -h|grep "/dev/ram0"|awk '{
temp=$4;
if(temp ~ /G$/) print 1;
else if(temp ~ /M$/) {
sub("M","",temp);print "#"temp"#";
if(temp > 300) print 1;else print 0;
}
}'
#1020#
0
神马问题,1020不大于300 ?
作者: hover_sky 发布时间: 2011-06-03
本帖最后由 hover_sky 于 2011-06-03 15:21 编辑
df -h|grep "/dev/ram0"|awk '{
temp=$4;
if(temp ~ /G$/) print 1;
else if(temp ~ /M$/) {
sub("M","",temp);print "#"temp"#";
if ( int(temp) > 300 ) print 1;else print 0;
}
df -h|grep "/dev/ram0"|awk '{
temp=$4;
if(temp ~ /G$/) print 1;
else if(temp ~ /M$/) {
sub("M","",temp);print "#"temp"#";
if ( int(temp) > 300 ) print 1;else print 0;
}
作者: hover_sky 发布时间: 2011-06-03
本帖最后由 jason680 于 2011-06-03 15:17 编辑
$ echo "1 2 3 1200M" | awk '{temp=$4;sub("M$","",temp);print temp;if(temp > 300)print "Yes";else print "No";}'
1200
Yes
$ echo "1 2 3 1200M" | awk '{temp=$4;sub("M$","",temp);print temp;if(temp > "300")print "Yes";else print "No";}'
1200
No
可能是版本问题....
$ awk -W version
GNU Awk 3.1.6
Copyright (C) 1989, 1991-2007 Free Software Foundation.
QUOTE:
# df -h|grep "/dev/ram0"|awk '{
temp=$4;
...
hover_sky 发表于 2011-06-03 14:49
temp=$4;
...
hover_sky 发表于 2011-06-03 14:49
$ echo "1 2 3 1200M" | awk '{temp=$4;sub("M$","",temp);print temp;if(temp > 300)print "Yes";else print "No";}'
1200
Yes
$ echo "1 2 3 1200M" | awk '{temp=$4;sub("M$","",temp);print temp;if(temp > "300")print "Yes";else print "No";}'
1200
No
可能是版本问题....
$ awk -W version
GNU Awk 3.1.6
Copyright (C) 1989, 1991-2007 Free Software Foundation.
作者: jason680 发布时间: 2011-06-03
ascii 比较, 1 小于 3
else if(temp ~ /M$/) {
if ( temp+0 > 300 ) print 1;else print 0;
}
else if(temp ~ /M$/) {
if ( temp+0 > 300 ) print 1;else print 0;
}
作者: ly5066113 发布时间: 2011-06-03
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28