I need to remove an extra pipe character at the end of header row of a pipe delimited csv file with sed. The literal string that I am trying to find is COLNAME|
Working on a GCP Windows server. The command I am trying to use:
"C:\Program Files (x86)\GnuWin32\bin\sed.exe" sed '0,/COLNAME"|"/s//COLNAME/' FILENAME
returns the output... sed.exe: -e expression #1, char 3: unterminated `s' command
I'm new to sed and have been playing around with the s command for a while but cannot seem to get the syntax correct.
Any suggestion on how to accomplish this?
If you want to replace
COLNAME|withCOLNAME"|"in Windows, using the GNUsed, you can useHere,
COLNAME|matchesCOLNAME|andCOLNAME"^""|"^""forms the literalCOLNAME"|"replacement sinceCOLNAME"ends the quoted string,^"appends a literal"char to the sed command,"|"appends a|char to the sed command and then^"appends another literal"to the sed command, and the next"starts the finishing part. Thegflag makes it match and replace all occurrences.If you want to replace
COLNAME"|"withCOLNAMEin Windows, using the GNUsed, you can do that withMind that you need to enclose the substitution command with double quotes and to match a double quote, you can't simply use a
"or a\", you can match it with an escaped^", or with\x22, a hex reprentation of the char, or\d34.Note that in
"s/COLNAME"^""|"^""/COLNAME/g", the sed command is built in the following way:"s/COLNAME"sets the beginning^"appends a literal"char to the sed command"|"- adds|pipe char^"- adds another""/COLNAME/g"- finishes off the sed command with the replacement and the global modifier/flag.