尝试将一些屠宰数据转换为条形分隔,未经删除的数据......
这里是一些示例数据
asd1276vdjs12897364vsk Tue Apr 2 08:19:12 2013 [pid 3] [words] FAIL UPLOAD: Client "00.005.006.006", "/0801NSJH.bbf", 0.00Kbyte/sec
到
asd1276vdjs12897364vsk|Tue Apr 2 08:19:12 2013|[pid 3]|[words]|FAIL UPLOAD: Client "00.005.006.006"|"/0801NSJH.bbf"|0.00Kbyte/sec
正则表达式很简单,但我不知道怎么说first field = regex, second field = regex
等。
这个sed很实用,但有点像hacky,我想让它在gawk中工作。
sed 's/ Sun/|Sun/'
sed 's/ Mon/|Mon/'
sed 's/ Tue/|Tue/'
sed 's/ Wed/|Wed/'
sed 's/ Thu/|Thu/'
sed 's/ Fri/|Fri/'
sed 's/ Sat/|Sat/'
sed 's/ Sun/|Sun/'
sed -e 's% \[%|\[%g' -e 's%\] %\]|%g' -e 's%, %|%g'
答案 0 :(得分:1)
$ cat tst.awk
{ print gensub(/\
([^[:space:]]+)[[:space:]]+\
([^[]+)[[:space:]]+\
([[][^]]+[]])[[:space:]]+\
([[][^]]+[]])[[:space:]]+\
([^,]+),[[:space:]]+\
([^,]+),[[:space:]]+\
/,
"\\1|\\2|\\3|\\4|\\5|\\6|","")
}
$ awk -f tst.awk file
asd1276vdjs12897364vsk|Tue Apr 2 08:19:12 2013|[pid 3]|[words]|FAIL UPLOAD: Client "00.005.006.006"|"/0801NSJH.bbf"|0.00Kbyte/sec