Something like dos2unix for windows?

I have several shell scripts created for windows and I want to run dos2unix for them.

But since I read that dos2unix works on Linux , is there a way I can convert my files to UNIX format while working on Windows?

I already installed CYGWIN, but I am having some problems, such as

 Administrator@S GH735082N ~ $ pwd /home/Administrator Administrator@SGH735082N ~ $ cd C:\CVS Code Administrator@SGH735082N /cygdrive/c/CVS $ dos2Unix BLPDB000 BLPDB000: dos2Unix processing BLPDB000: No such file or directory Administrator@SGH735082N /cygdrive/c/CVS $ dos2Unix -h dos2Unix: bad argument -h: unknown option Administrator@SGH735082N /cygdrive/c/CVS $ dos2Unix --help dos2Unix version 0.1.3 converts the line endings of text files from DOS style (0x0d 0x0a) to UNIX style (0x0a) Usage: dos2Unix [OPTION...] [input file list...] Main options (not all may apply) -A, --auto Output format will be the opposite of the autodetected source format -D, --u2d Output will be in DOS format --unix2dos Output will be in DOS format -U, --d2u Output will be in UNIX format --dos2unix Output will be in UNIX format --force Ignore binary file detection --safe Do not modify binary files Help options -?, --help Show this help message --usage Display brief usage message --version Display version information --license Display licensing information Other arguments [input file list...] for each file listed, convert in place. If none specified, then use stdin/stdout Administrator@SGH735082N /cygdrive/c/CVS $ Administrator@SGH735082N /cygdrive/c/CVS $ dos2Unix -oBLPDB000 dos2Unix: bad argument -oBLPDB000: unknown option Administrator@SGH735082N /cygdrive/c/CVS $ dos2Unix -k BLPDB000 dos2Unix: bad argument -k: unknown option Administrator@SGH735082N /cygdrive/c/CVS $ dos2Unix BLPDB000.txt BLPDB000.txt: dos2Unix processing BLPDB000.txt: No such file or directory Administrator@SGH735082N /cygdrive/c/CVS $ pwd /cygdrive/c/CVS 
+15
source share
8 answers

You can use Notepad ++ .

The instructions for recursively transforming a directory are as follows:

  1. Menu: Search โ†’ Find in Files ...
  2. Directory = the directory you want to convert to Unix format, recursively. For example, C: \ MyDir
  3. Find what = \ r \ n
  4. Replace with = \ n
  5. Search Mode = Advanced
  6. Click Replace in Files
+10
source

If you have perl installed, you can simply run:

 perl -i -p -e "s/\r//" <filename> [<filename2> ...] 
+6
source

There are at least two resources:

  • dos2unix on SourceForge , which seems to be actively supported (as of 2015) and has pre-compiled releases for Windows, both 32-bit and 64-bit. Also includes unix2dos, mac2unix and unix2mac.
  • GnuWin32 CygUtils , which are various utilities branched from Cygwin, which includes dos2unix, as well as several other related utilities. This package is not actively supported (the last update was in 2008).
+6
source

I used grepWin :

  • Open the folder with your files in grepWin
  • In the Search section
    • select "Regex Search"
    • Search โ†’ \r\n
    • Replace with โ†’ \n
  • Click Search to confirm which files will be affected, then Replace.
+1
source

You are using a very old version of dos2unix on Cygwin. Cygwin 1.7 has changed to a new version of dos2unix, the same thing that comes with most Linux distributions about two years ago. Therefore, update dos2unix using the Cygwin installer. Verify that you are getting version 6.0.3.

There are also native dos2unix Windows ports available (win32 and win64). See http://waterlan.home.xs4all.nl/dos2unix.html

Yours faithfully,

0
source

Any good text editor in Windows supports saving text files using only line feeds as line endings.

To automatically convert text files from DOS / Windows to UNIX line endings, the JREPL.BAT batch file , written by Dave Benham , is a hybrid batch file / JScript file used to replace regular expressions in a file using JScript. even on Windows XP.

One file can be converted from DOS / Windows to UNIX using, for example:

 jrepl.bat "\r" "" /M /F "Name of File to Modify" /O - 

In this case, all carriage returns are deleted from the file for modification. Of course, it would also be possible to use "\r\n" as the search string and "\n" as the replacement string to remove only the carriage return left by the line feed if the file contains the carriage return also somewhere else that should not be removed when converting string delimiters.

Multiple files in a directory or a whole directory tree can be converted from DOS / Windows to UNIX text files using the FOR command for the CALL JREPL.BAT batch file for each file of the corresponding template template.

An example batch file for converting all * .sh files in the current directory from DOS / Windows to UNIX.

 @for %%I in (*.sh) do @call "%~dp0jrepl.bat" "\r" "" /M /F "%%I" /O - 

The batch file JREPL.BAT must be stored in the same directory as the batch file containing this command line.

To understand the commands used and how they work, open a command prompt window, run the following commands there and fully read all the help pages displayed for each command.

  • jrepl.bat/?
  • call/?
  • for/?
0
source

Solved this via Notepad ++.

Go to: Edit -> EOL Conversion -> Unix.

0
source

There are so many solutions in PowerShell, given the many tools on the .NET platform

With the file path in $file = 'path\to\file' we can use

 [IO.File]::WriteAllText($file, $([IO.File]::ReadAllText($file) -replace "'r'n", "'n")) 

or

 (Get-Content $file -Raw).Replace("'r'n","'n") | Set-Content $file -Force 

To do this for all files, just pass the list of files to the above commands:

 Get-ChildItem -File -Recurse | % { (Get-Content -Raw -Path $_.Fullname).Replace ("'r'n", "'n") | Set-Content -Path $_.Fullname } 

Cm

For large files, you can use buffering solutions in Replace CRLF with powershell

0
source

Source: https://habr.com/ru/post/959304/


All Articles