Insert newline (\n) using sed

前端 未结 4 1072
忘掉有多难
忘掉有多难 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:52

    Add a line after a match.

    The sed command can add a new line after a pattern match is found. The "a" command to sed tells it to add a new line after a match is found.

    sed '/unix/ a "Add a new line"' file.txt

    unix is great os. unix is opensource. unix is free os.
    
        "Add a new line"
        
        learn operating system.
        
        unixlinux which one you choose.
        
        "Add a new line"
    

    Add a line before a match

    The sed command can add a new line before a pattern match is found. The "i" command to sed tells it to add a new line before a match is found.

    sed '/unix/ i "Add a new line"' file.txt

    "Add a new line"
    
    unix is great os. unix is opensource. unix is free os.
    
    learn operating system.
    
    "Add a new line"
    
    unixlinux which one you choose.
    

提交回复
热议问题