Insert newline (\n) using sed

前端 未结 4 1077
忘掉有多难
忘掉有多难 2020-12-03 04:23

I am trying to scrub some lists into a properly formatted CSV file for database import.

My starting file, looks something like this with what is supposed to be each &

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 04:55

    The following works on Oracle Linux, x8664:

    $ echo 'foobar' | sed 's/foo/foo\n/'
    foo
    bar
    

    If you need it to match more than once per line, you'll need to place a g at the end, as in:

    $ echo 'foobarfoobaz' | sed 's/foo/foo\n/g'
    foo
    barfoo
    baz
    

提交回复
热议问题