Rearranging logfile with awk
Hello,
I want to rearrange one logfile to process it on one analytics tool. For this I've using commands like this: Code:
awk '{print $2,$1,$4,$7}' file.log Does anyone know how to avoid this problem? Thank you in advance |
you should show us some example: how your input lines look like, what causes the problem. Probably you only need to define a separator:
Code:
awk -F\ '{......}' logfile |
I think what the OP is saying, is that the log is something like:
Code:
1,Log,Blah,Blahs |
The log is like this:
Quote:
Thank you for your anwsers |
in your case you can try something like this:
awk ' { $3 = $1; $1 = ""; $5 = ""; $6 = ""; print } ' or you can use perl, that will keep $7 in one piece. |
Please identify what version of awk are you using?
Code:
awk --version |
In a more general case, you should try the following awk code:
Code:
BEGIN { Here is an example: Code:
$ cat file Code:
$ awk 'BEGIN{ FS = OFS = "\"" }{ for ( i = 2; i < NF; i += 2 ) gsub(/ +/, "\033", $i); split($0, m, " "); for ( i = 1; i <= length(m); i++ ) gsub("\033", " ", m[i]); print m[2] " " m[1] " " m[4] " " m[7] }' file |
Quote:
Code:
awk 'BEGIN{ FS = OFS = "\"" }{ for ( i = 2; i < NF; i += 2 ) gsub(/ +/, "\033", $i); split($0, m, " "); for ( i = 1; i <= length(m); i++ ) gsub("\033", " ", m[i]); print m[1] " " m[2] " " m[5] " " m[12] " " m[8] " " m[6] " " m[16] " " m[4] " " m[3] " " m[7] " m[9] }' Code:
^ unfinished string |
probably this works for you:
Code:
perl -ne ' @a = split (/ /, $_, 7); print "$a[1] $a[0] $a[3] $a[6]" ' file.log |
All times are GMT -5. The time now is 10:28 AM. |