How to replace crlf with lf in one file

How to convert single crlf line return file to return lf line?

git already correctly handles crlf to convert lf automatically for files when I push them to a remote repository, but in this particular case I do not push to the repository. Rather, I upload a file using a file field in an HTML form to a website that requires the file to return the string lf. Therefore, I need to be able to convert this file separately.

My available potentially useful tools available on this computer will be git and Dreamweaver CC 2014.1. (I assume that Word, Wordpad, and Notepad are not viable options, but I'm open to fixing it.)

I am on Windows 7 and using git commands.

+13
git windows
source share
6 answers

Installing git on windows usually includes the dos2unix tool in dos2unix .

 dos2unix <file> 

But in your case, you should use .gitattributes to prevent the file from being converted to Windows.

A .gitattributes file might look like this

 *.vcproj eol=crlf *.sh eol=lf 

From the .gitattributes documentation

Set string value to "lf"

This parameter causes Git to normalize line endings in LF during registration and prevents conversion to CRLF when extracting the file.

Just commit the .gitattributes file and your file will be .gitattributes on each system with the end of the LF line.

+16
source share

To convert from Windows-style text to Unix-style text:

 perl -pe 's/\r$//g' < windows_file.txt > unix_file.txt 

To convert Unix-style text to Windows-style text:

 perl -pe 's/(?<!\r)\n/\r\n/g' < unix_file.txt > windows_file.txt 

This "Unix-to-Windows" command is "safe", and I mean that it will not add extra carriage returns to a file that is already in Windows format. I hope someone takes advantage of this.

+2
source share

Word and wordpad should be avoided! NEVER try to change the code with it, they will add additional code for the file.

To convert the end of a line, you simply use Notepad ++ or Scite , you select the end of the file: Windows, Mac, Linux.

Here is an example of using Scite:

scite

+1
source share

For a single file, you can use the Notepad ++ replacement utility:

  • Go to Search β†’ Replace (or Ctrl-H)
  • In the dialog box, select "Advanced" search mode.
  • Set "Find What" to: \r\n
  • Set "Replace with" to: \n
  • Click Replace All
+1
source share

In Notepad ++, in the lower right pane, right-click the Windows area (CR LF) and select UNIX (LF), this should replace all CRLFs with LF.

enter image description here

+1
source share

convert to CR LF using this application http://www.softsea.com/review/U2WIN.html

0
source share

All Articles