Concatenate strings in awk

awk

Solution

If the log files Windows based, then you are almost certainly dealing with side-effects (affects? ;->) of the evil ^M char. It can defintely produce problems as you're describing.

 sub(/^M/,"", $0)

should help.

Thats a real Ctrl-M char and not 2 chars'^','M', produced in a vi compliant editor by pressing Ctrl-V and tne Ctrl-M.

I hope this helps.

Problem

I have a log file which I need to "replay" on the server. It contains entries like this: ``` Request: query: EXEC prc_insert_customer @param0: 110040851 @param1: 137463 @param2: user@example.com @param3: John @param4: Smith @param5: Some address @param6: @param7: @param8: Some city @param9: GBR @param10: POSTCODE @param11: (555) 123-45-67 Response: ... ``` I need to convert each chunk like that into ``` EXEC prc_insert_customer '110040851', '137463', ..., '(555) 123-45-67' ``` I tried to use awk for that: ``` /EXEC prc_insert_customer/ { str = "EXEC prc_insert_customer"; } str && /@param/ { if ($1 == "@param0:") sep = "" else sep = "," str = ((str) (sep) " '"($2) ("'")) } /^Response/ { if (str) print str str = "" } ``` but the output I get is: ``` ', '(555)'DE', '', 'Some', 'GBR0851 ``` How do I get correct output? I use `GNU Awk 4.0.0` on `Fedora 17`.

Original source