awk - Setting one field at a time? -


trying turn butchered data bar delimited, unbutchered data...

here's sample data

asd1276vdjs12897364vsk tue apr  2 08:19:12 2013 [pid 3] [words] fail upload: client "00.005.006.006", "/0801nsjh.bbf", 0.00kbyte/sec 

into

asd1276vdjs12897364vsk|tue apr  2 08:19:12 2013|[pid 3]|[words]|fail upload: client "00.005.006.006"|"/0801nsjh.bbf"|0.00kbyte/sec 

the regex's simple enough, don't know how first field = regex, second field = regex etc.

this sed functional kind of hacky, i'd make work in 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' 

$ 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 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -