Pulse Pulse - 5 months ago 7
Bash Question

Copy and pasted file names from finder on mac and vim showing ^M after each filename, how to fix?

I copy and pasted files from finder, into a text file to get the names of the files in a certain directory to a text file. When I open the file the files from each directory are all the same line...
For example: I copy and pasted from the "Hats Directory":
Line1 is:

hats1.jpg^Mhats2.jpg^Mhats3.jpg^M...


In that same text file I copy and pasted files from the "Shoes" directory
Line 2 is:

shoes1.jpg^Mshoes2.jpg^Mshoes3.jpg^M...


I have tried

:%s/^M//
dos2unix
CTRL-V CTRL-M


Neither of them work, am I going about this process the wrong one? Is there a more efficient way to do what I'm trying to do?

Answer

A more simple way is using bash truncate tr command.

Just do, tr -d '\r' < inputFile > outputFile to remove all the carriage return characters.

Comments