tags:

views:

49

answers:

1

I am trying to get SED to transform the output from a TMS320C55x compiler so that it is parsed correctly by Visual Studio (so that when you click an error/warning it jumps to the location in the source. I have done this successfully with other compilers, but do not use SED often enough for this to be painless, and this time it has defeated me.

The compiler output is of the form:

"<file>", line <line>: <error|warning> <id>: <text>

for example:

"ImageBuffer.c", line 21: error #20: identifier "p" is undefined

And I need it transformed to:

<file>(<line>) : <error|warning> <id>: <text>

so for the example above:

ImageBuffer.c(2) : error #20: identifier "p" is undefined

The critical thing is the () part.

Thanks.

+1  A: 

I can get that output by using:

c:\src>echo "ImageBuffer.c", line 21: error #20: identifier "p" is undefined
    | sed -e "s/\"//" -e "s/\", line /(/" -e "s/:/) :/"
ImageBuffer.c(21) : error #20: identifier "p" is undefined

I'm having to escape the " characters because I'm doing it from cmd.exe but you can use them unescaped in a more UNIXy environment if you just use single quotes to surround the sed commands.

The individual sed commands:

  • "s/\"//" gets rid of the starting quote from the file name.
  • "s/\", line /(/" gets rid of the ending quote from the file name and replaces the text between file name and line number with the opening parenthesis before the line number.
  • "s/:/) :/" puts the closing parenthesis after the line number after removing some other unnecessary text.
paxdiablo
Thanks. I am using cmd.exe too (implicit perhaps since this is for Visual Studio compatibility). This worked out-of-the box. Your solution is far simpler than the regex I had, but I think my real problem was my use of ' delimiters rather than " since all the examples were for *nix shell environments. Doh!
Clifford
I wasn't sure which sed you were using. If you were running Cygwin, single quotes would work fine within its bash shell. I, on the other hand, run MinGW from cmd.exe so I'm a bit limited there. Glad I could help.
paxdiablo