Home:ALL Converter>Anything like dos2unix for Windows?

Anything like dos2unix for Windows?

Ask Time:2013-12-04T14:43:38         Author:Elvin

Json Formatter

I have some shell scripts created on Windows. I want to run dos2unix on them.

I have read that dos2unix works on Linux.
Is there a way that I can convert my files to having Unix newlines while working on Windows?

Author:Elvin,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20368781/anything-like-dos2unix-for-windows
Erwin Waterlander :

You are using a very old dos2unix version on Cygwin. Cygwin 1.7 changed to a new version of dos2unix, the same as is shipped with most Linux distributions, about two years ago. So update your dos2unix with Cygwin's setup program. Check you get version 6.0.3.\n\nThere are also native Windows ports of dos2unix available (win32 and win64).\nSee http://waterlan.home.xs4all.nl/dos2unix.html\n\nregards,",
2013-12-04T08:35:22
Ahmad Boorghany :

You can use Notepad++.\nThe instructions to convert a directory recursively are as follows:\n\nMenu: Search -> Find in Files...\nDirectory = the directory you want to be converted to Unix format, recursively. E.g., C:\\MyDir\nFind what = \\r\\n\nReplace with = \\n\nSearch Mode = Extended\nPress "Replace in Files"\n",
2017-11-22T06:34:19
kle10 :

Solved it trough Notepad++.\n\nGo to: Edit -> EOL Conversion -> Unix.",
2019-07-19T14:57:38
shx2 :

If you have perl installed, you can simply run:\n\nperl -i -p -e \"s/\\r//\" <filename> [<filename2> ...]\n",
2013-12-04T07:03:42
Mike T :

There are at least two resources:\n\n\ndos2unix on SourceForge, which appears to be actively maintained (as of 2015), and has pre-compiled releases for Windows, both 32- and 64-bit. Also includes unix2dos, mac2unix, and unix2mac.\nCygUtils from GnuWin32, which are miscellaneous utilities forked from Cygwin, which includes dos2unix as well as several other related utilities. This package is not actively maintained (last update was in 2008).\n",
2015-08-13T22:21:22
phuclv :

In PowerShell there are so many solutions, given a lot of tools in the .NET platform\nWith a path to file in $file = 'path\\to\\file' we can use\n\n[IO.File]::WriteAllText($file, $([IO.File]::ReadAllText($file) -replace "`r`n", "`n"))\n\nor\n(Get-Content $file -Raw).Replace("`r`n","`n") | Set-Content $file -Force\n\nIt's also possible to use -replace "`r", "" instead\nTo do that for all files just pipe the file list to the above commands:\nGet-ChildItem -File -Recurse | % { (Get-Content -Raw `\n -Path $_.Fullname).Replace ("`r`n", "`n") | Set-Content -Path $_.Fullname }\n\nSee\n\nhow to convert a file from DOS to Unix\nHow to convert DOS line endings to UNIX on a Windows machine\nPowershell v2: Replace CRLF with LF\n\nFor bigger files you may want to use the buffering solutions in Replace CRLF using powershell",
2019-09-04T15:46:17
Antonio :

I used grepWin:\n\n\nOpen the folder containing your files in grepWin\nIn the \"Search for\" section\n\n\nselect \"Regex search\"\nSearch for -> \\r\\n\nReplace with -> \\n\n\nHit \"Search\" to confirm which files will be touched, then \"Replace\".\n",
2018-05-08T23:09:39
Ben Saunders :

The search and replace Regex didn't work for me for whatever reason, however solved on single file (~/.bashrc) in Notepad++ by setting Encoding --> UTF-8 and resaving. Not as scalable but hopefully saves some headaches for quick conversion.",
2021-04-16T20:51:47
Rishab Jula :

\nOpen the file using Notepad++\nHit Ctrl+F\nSelect search mode as "Regular Expression"\nSearch for -> \\r\\n\nReplace with -> \\n\nHit "Replace all" under the "Replace tab"\n\nif the above doesn't work -\nmvn clean install",
2021-03-19T07:21:52
BuvinJ :

I realize this may be a bit of a contextual leap, but I'll share my thought anyway since it just helped in my use case...\nIf the file will live in a git repo, you can enforce the line endings on it via a .gitattributes file. See: how to make git not change line endings for one particular file?",
2021-12-29T01:06:20
yy