I've always been intimidated by perl, but your code worked perfectly, Walt.
You can also do this in Perl of course. It's unclear to me whether Casey wants to completely remove the CR-LF-Space sequence or replace it with just a LF. To remove it, use
perl -0777 -pe 's/\r\n //g'
To replace it with a line feed, use
perl -0777 -pe 's/\r\n /\n/g'
The -pe
flags together tell Perl to read in every line of stdin and apply a regular _expression_ to them. The
-0777
flag tells it to slurp in the entire stream as a single line. The regex replaces the CR-LR-Space sequence globally with either nothing or
a newline.
On Mon, Jun 12, 2023 at 09:03:34AM -0400, Aaron Mulder via plug wrote:
> There's a Stack Overflow question with several possible answers (obscure
> sed syntax, workarounds, Perl, etc.) but here's the answer that looks
> On Mon, Jun 12, 2023 at 8:23 AM Casey Bralla (Mail List) via plug <
> > I'm trying to manipulate my on-line caldav calendar data, but am having
> > trouble with some of the formatting of the raw calendar file. I need
> > help in removing a CR-LF-Space 3-character sequence from the downloaded
> > I'm using a wget command to download the calendar file, which works
> > well. Unfortunately, when caldav dumps the "DESCRIPTION" element, it
> > limits it to 72 columns, and adds a CR-LF-Space to continue the data
> > field. I'm looking for a way to eliminate this 3-character sequence
> > from the wget'd file. If I could do that, each data element would be on
> > a single line, and very easy to parse and manipulate.
> > My first thought was to pipe wget through sed, but sed deals with
> > individual lines, and so it never sees the CR-LF-Space sequence on a
> > single line and therefore can't do a substitution on it.
> > I could also write a python script to edit the data, but that seems too
> > complicated. I assume there must be a simple way to edit this sequence
> > using a sed-equivalent that works on entire files, not just individual
> > lines. Ideally, I'd do this as a piped operation when I wget the file.
> > How can I easily (simply) search and replace a CR-LF-SPACE 3-character
> > sequence from a text file using the command line?
> > LEGAL NOTICE: This eMail contains private, personal, and/or privileged
> > information and is only for the intended recipient(s). In fact, you
> > really should consider yourself honored to even be cc'd on this
> > tremendously important communication. The author spent literally
> > seconds composing this magnificent opus of rational thought and
> > deductive logic. Unfortunately, it has probably been based on
> > inaccurate data, which really stinks because this eMail would have been
> > truly awesome! If you have received this eMail in error, we
> > respectfully DEMAND that you immediately delete it and inform the sender
> > that you have received it in error. Then, just to be safe, you should
> > reformat your hard drive, shave your head, renounce all material
> > possessions (which are really controlling your life anyway), and join an
> > end-of-times cult somewhere. Once there, you must reconsider all the
> > terrible choices you've made in your life, and promise never to confuse
> > "sex" with "gender" again. Of course, this assumes you have already
> > come to terms with your inherent whiteness, AND that you have learned
> > the lyrics to The Internationale. "Arise, wretched of the earth! Arise,
> > convicts of hunger..."
> > We sincerely hope you are able to get your medication stabilized and no
> > longer have that recurring dream where you're alone in a large crowd,
> > standing naked in a vat of chocolate Yoo-hoo. BTW, Yoo-hoo really is an
> > underrated beverage. It’s chocolatey, yet suprisingly refreshing. Pick
> > up a 6-pack today, and tell your friends!
> > ___________________________________________________________________________
> > Philadelphia Linux Users Group --
> > General Discussion --
> ___________________________________________________________________________
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug