How do I insert line breaks into a text file - not programming, not fixed width - via find & replace

80,523

Solution 1

Using sed:

sed -e 's/:/\n/g' foo.txt

Solution 2

I assume that if you have Excel, you have Word....

You can add line breaks from the Find/Replace function in Word 2010 - make your CSV a .txt and go to town. Under Find/Replace click the "More >>" button and then the special drop down box to insert a line break as a replacement for ":"

You can also accomplish this with NoteTab; you would run a replace-all command, replacing ";" by \r\n -- but be sure to check the "regular expression" box.

"\" is a prefix to indicate regular expression codes and special characters. "\r" is a carriage return and "\n" is a line-feed; the pair forms a Windows newline.

Share:
80,523

Related videos on Youtube

Community
Author by

Community

Updated on September 18, 2022

Comments

  • Community
    Community almost 2 years

    This is a different from someone else's similarly-titled question. Neither Excel nor OpenOffice allow users to specify line delimiters, so I'm trying to replace semi-colons with line breaks. How do I edit the code of a text file?

    In Notepad I tried replace ; with /n. I didn't think it would work; and it didn't. My long single-line txt/~csv file is crying: Help!

    • Admin
      Admin almost 13 years
      So you dont want to do this programmatically? But you want to take a file with breaks indicated with semi-colons and change those semi colons to actual line breaks through find and replace?
  • Jjames
    Jjames almost 11 years
    Is that a typo that you inserted a colon instead of a semi colon? Also that -e is not necessary in this case.