0

I have a sed command as follows:

sed -i 's/),(/),\n(/g' myfile

myfile is like this:

(237),(238)

The expected result is:

(237),
(238)

The actual result is:

(237),n(238)

I have tried many ways to write new line, but all failed. Is it possible to get the expected result?

I found that GNU sed works, but BSD sed not.

lutaoact
  • 4,149
  • 6
  • 29
  • 41

2 Answers2

1

for BSD sed, we can write new line as $'\n', so the command should be:

/usr/bin/sed 's/),(/),\'$'\n''(/g' myfile
lutaoact
  • 4,149
  • 6
  • 29
  • 41
0

This might work for you:

sed -e 'G' -e 's/,\(.*\)\(.\)/,\2\1/' file

The G command will append the hold space to the pattern space, which in effect will, as the hold space is empty, append a newline. Pattern matching can re-arrange this to the desired result.

potong
  • 55,640
  • 6
  • 51
  • 83