Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'fixing Mac line breaks w/ PERL (MULTIPLE FILES)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
fixing Mac line breaks w/ PERL (MULTIPLE FILES)
Authored by: CrazyDuke on Apr 20, '02 02:00:52PM

I found that I needed to do like 100 at a time and it wasn't going to cut it to pass one file at a time. This is what I did:

1. if you don't have a bin directory in your home directory make one go to the terminal and tyep "mkdir bin"
2. the in the bin directory create a file called 'fle' with your favorite editor and then put in this one line:

for T in `ls -a $*`; do perl -pi -e 's/rn?/n/g' $T; done

I chose "T" for no particular reason.

3. Save he file and in the terminal type: chmod 755 fle while in the bin directory.
4. If you want to use it right away, you need to first close whatever terminal window you're using and open a new one. For some reason when creating new shell scripts this has to be done before you can execute them.

That's it. Now when you want to do a whole directory you can do:

fle * (or simply fle by itself)

or specify file-names: fle *.php or fle myfile.txt

it will work with one or mulitple files.



[ Reply to This | # ]
fixing Mac line breaks w/ PERL (MULTIPLE FILES)
Authored by: Seth Milliken on Sep 04, '03 02:25:39PM

You don't have to close your terminal. Just type "rehash". Note also that the path to your bin directory has to be in your PATH for this to work.



[ Reply to This | # ]
fixing Mac line breaks w/ PERL (MULTIPLE FILES)
Authored by: mmarlett on Jan 02, '05 05:01:04PM

A somewhat more helpful (for me) version of this script reads like this:

######
#!/bin/sh
for filename in *.TXT
do
         echo $filename
         perl -pi -e 's/rn?/n/g' "$filename"
done
#######

The -li is unnecessary and the files I happen to want to deal with are of the TXT sort. However, * would cover everything as well.

The important change, though, is the quotes around $filename (or $T in the above example) so that file names with spaces in them are handled correctly by perl.

[ Reply to This | # ]

fixing Mac line breaks w/ PERL (MULTIPLE FILES)
Authored by: beatmacman on Oct 02, '06 09:30:15AM
Actually, even easier command, using find:

find . -type f -name "DEMO*" -exec perl -pi -e 's/\r/\n/g' \{\} \;

this changes all files starting with "DEMO". Obviously, you can change that to "*" or whatever suits your needs.

[ Reply to This | # ]