Need to replace a comma followed by space with a newline
On LINUX I see people posting examples such as
sed 's/,\s/\n/g' textfile
Whereas in MacOSX this doesn't work but the following does
sed 's/, /\
/g' testfile
The space as in real space and the newline character is an actual backslash with a newline 'entered'
What am i doing wrong ?
On OSX you can do:
sed -i.bak 's/, /\'$'\n''/g' file
Or this:
sed -i.bak $'s/, /\\\n/g' file
As per man bash
:
Words of the form $'string' are treated specially. The word expands to string,
with backslash-escaped characters replaced as specified by the ANSI C standard.
Backslash escape sequences, if present, are decoded as follows:
\a alert (bell)
\b backspace
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\' single quote
\nnn the eight-bit character whose value is the octal value nnn
(one to three digits)
\xHH the eight-bit character whose value is the hexadecimal value HH
(one or two hex digits)
\cx a control-x character
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.