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


Click here to return to the 'An alias that uses perl' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An alias that uses perl
Authored by: TheGS on Mar 06, '02 10:47:32PM
Rather than loading a file into a text editor (like emacs or BBEdit), I have an alias set up that does the conversion, using perl instead:

alias mac2unix "perl -pi -e 'tr/\015/\012/' \!*"

And then I can use it directly from the command line:

% mac2unix MacTextFile.txt ...



[ Reply to This | # ]
An alias that uses perl
Authored by: TheGS on Mar 07, '02 12:00:15AM
Somebody else suggested that a drag-and-drop tool would be useful. Here's a quick AppleScript droplet that accepts files dropped onto it (ignoring directories) and then passes the absolute path of each file to a one-line perl script.
 on open fileList
   repeat with x in fileList
     if folder of (info for x) is not true then
       set y to POSIX path of x
       do shell script ("perl -pi -e \"tr/\\015/\\12/\" " & y)
     end if
   end repeat
 end open


[ Reply to This | # ]
An alias that uses perl
Authored by: oink on Mar 08, '02 01:55:31PM

can I use Logan's "alias mac2unix="perl -p0015l0012e '' -i $*"" with this script

on open fileList
repeat with x in fileList
if folder of (info for x) is not true then
set y to POSIX path of x
do shell script ("perl -p0015l0012e '' -i" & y)
end if
end repeat
end open

doesn't work... no error, just wouldn't convert.

Thanks



[ Reply to This | # ]
An alias that uses perl
Authored by: TheGS on Mar 08, '02 09:05:18PM

You might be missing a space between the '-i' and the path to the file.



[ Reply to This | # ]
An alias that uses perl
Authored by: logan on Mar 07, '02 12:15:36AM
Yeesh. A one-liner? How about a zero-character script that does the same thing? ;)
alias mac2unix="perl -p0015l0012e '' -i $*"


[ Reply to This | # ]
An alias that uses perl
Authored by: TheGS on Mar 07, '02 12:25:27AM

I like yours better — there's less time wasted compiling that 'tr' operation. TMTOWTDI, in any case.



[ Reply to This | # ]
An alias that uses perl
Authored by: oink on Mar 08, '02 01:52:48PM

re: alias mac2unix="perl -p0015l0012e '' -i $*"

Hmm, wow.

Now all I need is to fit this into an applescript, the following doesn't work.

on open fileList
repeat with x in fileList
if folder of (info for x) is not true then
set y to POSIX path of x
do shell script ("perl -p0015l0012e '' -i" & y)
end if
end repeat
end open




[ Reply to This | # ]
An alias that uses perl
Authored by: ret on Mar 14, '02 09:35:34PM

That's an l (lower case "L"), not a "|" pipe. See what a difference that makes to your script.

cheers
RET



[ Reply to This | # ]