On 2013-07-29 at 5:00 PM, [email protected] (Rick Gordon) wrote:
Wouldn't that change multiple returns to a single return, as well, though?
It would.
Just in case anyone's interested, ss long as we're using Perl,
here's the "canonical" way to convert from any* line-ending to
the one you want, including in files with mixed line-endings.
*Any line ending in widespread use today. And this won't be true
forever, as the world eventually converts to UNICODE line-ending constructs.
This uses octal \015 for CR (Carriage Return) and \012 for LF
(Line Feed).
Substituting in for John's one-liner, but NOT reducing blank lines:
perl -pi.bak -e "s~\015?\012|\015~\n~g"
The expression \015?\012|\015 matches every instance of:
\015\012 CRLF Dos/Win
\012 LF UNIX (including OS X), VMS
\015 CR old Mac
If you DID want to reduce multiple line-endings to single ones, try:
perl -pi.bak -e "s~(\015?\012|\015)+~\n~g"
The Perl substitutions above replace every one of those matches
with the OS-native line-ending, written as \n in Perl. (Remember
that we're talking about Perl and your operating system. In
BBEdit, \n and \r are now interchangeable symbols in search
patterns, but previously meant LF and CR.)
If you are sure you know what system your file will be used on,
you could use the octal character expression for the replacement
pattern. So for UNIX/OS X/Linux resulting line-endings:
perl -pi.bak -e "s~\015?\012|\015~\012~g"
BTW, that Perl expression, while beautiful in its power to some
of us, must be obscure to others. John's more adept than I at
laying out the step-by-step explanation, but if someone requests
it, one of us would probably respond...
HTH
------------------
On 7/30/13 at 12:28 AM +0100, John Delacour wrote in a message
entitled "Re: Searching for files of a particular line break type":
On 29/7/13 at 21:06, [email protected] (Robert A. Rosenberg) wrote:
One warning. If you want to change CR to LF (as in this
suggestion), you have to watch out for the CR+LF Line ending since
just changing CR to LF will make this LF+LF.
This will change _any_ line ending to \n :
perl -pi.bak -e "s~[\r\n]+~\n~g" *
Best Regards,
- Bruce
_bruce__van_allen__santa_cruz_ca_
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].