Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Macintosh Line Breaks to UNIX

Status
Not open for further replies.

stringtheory3

Technical User
Aug 27, 2008
3
US
I am converting files in a process that requires a few different perl scripts. Before the final step, I need to save all the files from Macintosh line breaks to UNIX line breaks. Then at the end, I need to change the line breaks back to Macintosh (so the file can be imported into InDesign).

I can do this to files individually by opening them in TextWarangler and doing "save as," but I'd like to be able to do this automatically to the whole group. Is there a perl script that can do this?
 
well if you know what they are you can do a substitution
s///g;
or
tr///g;
which every meets your needs

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
A quick google search turned up this.

To convert a Mac OS text file to a Unix text file using Perl, at the Unix shell prompt, enter:

perl -p -e 's/\r/\n/g' < macfile.txt > unixfile.txt
To convert from a Unix text file to a Mac OS text file with Perl, at the Unix shell prompt, enter:

perl -p -e 's/\n/\r/g' < unixfile.txt > macfile.txt
If you want it in a script rather than command line, the substitution should work for you.
 
The first suggestion doesn't work. It tells me there are compilation errors.

The second suggestion only works for individual files. While I can put in the individual files' names and make the conversion using that command line, it would be simpler just to open the file and do a "save as."

Is there any way to apply that command to a group of files in a folder, rather than just to an individual file?

thanks
 
Never mind - I was wrong. That first suggestion DOES work. My mistake was that the script was looking for files with the extension of .idtt while they still had the .txt extension. When I fixed that, the conversion went great.

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top