1

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?

Inian
  • 80,270
  • 14
  • 142
  • 161
Pulse
  • 527
  • 4
  • 11

4 Answers4

3

A more simple way is using bash truncate tr command.

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

Inian
  • 80,270
  • 14
  • 142
  • 161
2

Try this command:

:%s/^M//g

The ^M that you are looking for is ctrl+V Enter

1

These are old style mac line breaks (a single \r). Try mac2unix

0

You could get that list without involving the Finder and without fishy formatting:

:r!ls path/to/dir

See :help :r and :help :!.

romainl
  • 186,200
  • 21
  • 280
  • 313