日期:2014-05-16  浏览次数:20593 次

awk 替换 匹配

原文:http://liveforlinux.blog.51cto.com/3337218/741865

[root@localhost test]# cat awk

1a 9,100.34
1b 1,999.00
1c 5,656.55
[root@localhost test]# awk '{sub(/1/,"test")}{print "\n",$1,$2}' awk   
testa 9,100.34
testb 1,999.00
testc 5,656.55
[root@localhost test]# awk '{gsub(/1/,"test")}{print "\n",$1,$2}' awk  
testa 9,test00.34
testb test,999.00
testc 5,656.55
[root@localhost test]# awk '{sub(/[0-9]+/,"")}{print "\n",$1,$2}' awk 
a 9,100.34
b 1,999.00
c 5,656.55

打印出$1只包含4个字符的 awk '$1~/^....$/{print $1}' file

http://bbs.linuxtone.org/thread-17620-1-1.html 看到的学习一下记录一下 效果是有了 但时间和我系统时间对不上

[root@localhost test]# cat awk 
1a 9,100.34 dkjfjkdkjf 45  lopo
1b 1,999.00 dgfg       456 ll
1c 5,656.55 fghgf       465 df

[root@localhost test]# awk '{$2=strftime("%F %T",$2);print $1,$2,$3 >"bbb.txt";print $1,$2,$4 >"ccc.txt"}' awk
[root@localhost test]# cat bbb.txt 
1a 1969-12-31 16:00:09 dkjfjkdkjf
1b 1969-12-31 16:00:01 dgfg
1c 1969-12-31 16:00:05 fghgf
[root@localhost test]# date
Wed Dec 14 22:49:28 PST 2011
[root@lo