Python dos2unix one liner
@ Rocteur CC
macosx at rocteur.cc
Sat Feb 27 10:01:53 EST 2010
On 27 Feb 2010, at 12:44, Steven D'Aprano wrote:
> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote:
>
>> cat file.dos | python -c "import sys,re;
>> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in
>> sys.stdin]" >file.unix
>
> Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal
> string replacement! You've been infected by too much Perl coding!
Thanks for the replies I'm looking at them now, however, for those who
misunderstood, the above cat file.dos pipe pythong does not come from
Perl but comes from:
http://wiki.python.org/moin/Powerful%20Python%20One-Liners
> Apply regular expression to lines from stdin
> [another command] | python -c "import sys,re;
> [sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', line))
> for line in sys.stdin]"
Nothing to do with Perl, Perl only takes a handful of characters to do
this and certainly does not require the creation an intermediate file,
I simply found the above example on wiki.python.org whilst searching
Google for a quick conversion solution.
Thanks again for the replies I've learned a few things and I
appreciate your help.
Jerry
More information about the Python-list
mailing list