我想使用awk / sed格式化输出,但我无法理解如何操作。我正在使用以下命令:
uptime | awk '{print $1" " $2" " $3$4" " $6" " $10$11$12}'
15:36:17 up 177days, 7 0.39,0.43,0.36
我想要的输出是
15:36:17 up 177days 7 0.39,0.43,0.36
我只想省略第一个逗号,即在" 177days"之后的那个逗号。
答案 0 :(得分:0)
使用sub
(用空字符串替换逗号)或substr
(使用除最后一个字符以外的所有字符串创建子字符串):
uptime | awk '{sub(",","",$4); print $1" " $2" " $3$4" " $6" " $10$11$12}'
uptime | awk '{print $1" " $2" " $3 substr($4,1,length($4)-1) " " $6" " $10$11$12}'
答案 1 :(得分:0)
尝试将命令的输出传递给sed
,该uptime | awk '{print $1" " $2" " $3$4" " $6" " $10$11$12}' | sed -r 's/(\w),/\1/'
匹配任何字母字符,后跟逗号,并将其替换为该字符:
List = ['F1',a,'F2',a,b,'F3',a,b,c,...]