Menu

How To? : removing line feeds

2007-05-14
2012-11-13
  • Nobody/Anonymous

    How do I remove line feeds from a file?

    I had a csv file opened which contained values with a LineFeed ($0a) in it. On the next line was a tab.

    I wanted to remove these line feeds, but couldn't manage to do this.

    If I selected the tab and the LF and pressed CTRL+R, it found only one, and I seemed not te be able to replace any of them. I also noticed I could nou check Selection or Wrap. Both options were disabled.

    I switched to Hex Edit mode, but was puzzled by the weird mix-up of the Find and Replace functionality (see the other thread about that).

    Finally, I managed to get what I wanted by copying the complete file to a new tab. Replace worked fine there. I copied the lot back and saved my file.

    Could this have something to do with LF/CR and/or Windows/Unix/Mac conversions?

     
    • pshute

      pshute - 2007-05-15

      Not sure if I totally understand your problem, but have you looked into the Convert To Windows, Mac or Unix Format options in the Format menu?

      Also have a look at http://notepad-plus.sourceforge.net/uk/newlineFindReplace-HOWTO.php for all the methods available for newline searching and replacing?  I've found the behaviour odd when I try to specify the search string by selecting it before starting the search and replace command, so I prefer to use control+R in non-regexp mode and use control+M and control+T to specify newlines and tabs.

       
    • Nobody/Anonymous

      Yup, I tried the Convert To options, but those seemed to have no effect at all.

      I am used to CTRL+R copying the selection, including LF/CR. Since that didn't function, I tried to simply replace characters in Hex Edit Mode. Later I had no problems with that.

      What should the effect be, when Converting to Windows, Mac or Unix? Should that be visible at once, or will this only affect the file when save, for instance?

       
      • pshute

        pshute - 2007-05-17

        "What should the effect be, when Converting to Windows, Mac or Unix? Should that be visible at once, or will this only affect the file when save, for instance? "

        It takes effect immediately.  If you have Show All Characters on, you should see this.

        In Windows format, lines have CR LF at the end.
        In Unix format, just LF.
        In Mac format, just CR.

         
    • Nobody/Anonymous

      Try search and replace with RegularExpressions:
      Look for: \r\n\t
      Replace with: \t
      This means: Look for CarriageReturn (CR), LineFeed (LF), and Tab; Replace with Tab (only)
      Depending on the format of your file, you may need to look only for "\r\t" or "\n\t". To find-out what is your file end-of-line sybmol(s), turn on "Show End Of Line" or "Show all characters" in the View menu - you will see "CR", "LF", or both at the end of all lines.

       
    • Nobody/Anonymous

      Yes, you remind me... I should have mentioned that I already have turned on "Show all characters". That's how I know I have to replace only the LF character.

       
MongoDB Logo MongoDB