我正在使用awk命令:
df -Pk | grep /var/prod/data | awk '{q=sprintf("%c", 39); print "INSERT INTO entity_trend(entity_name,entity_type,run_date,count) VALUES (\47DISKSPACE\47,\47SPACE\47,SYSDATE,"$5");";}' > cmd.sql
因此,cmd.sql的内容将是:
INSERT INTO entity_trend(entity_name,entity_type,run_date,count) VALUES ('DISKSPACE','SPACE',SYSDATE,**52%**);
相反,我想:
INSERT INTO entity_trend(entity_name,entity_type,run_date,count) VALUES ('DISKSPACE','SPACE',SYSDATE,**52**);
我应该如何形成substring命令?
答案 0 :(得分:1)
添加+0
以摆脱%
:$5+0
awk '{q=sprintf("%c", 39); print "INSERT... SYSDATE,"$5+0");";}' > cmd.sql
^^
查看示例:
$ echo "55%" | awk '{print $0}'
55%
$ echo "55%" | awk '{print $0+0}'
55