Walt Mankowski via plug on 12 Jun 2023 06:32:50 -0700
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] How to Eliminate a CR-LF-Space 3-Character Sequence from a Text File?
|
- From: Walt Mankowski via plug <plug@lists.phillylinux.org>
- To: plug@lists.phillylinux.org
- Subject: Re: [PLUG] How to Eliminate a CR-LF-Space 3-Character Sequence from a Text File?
- Date: Mon, 12 Jun 2023 09:32:06 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type; s=sasl; bh=zTD4jkSSrTuSSAaz3HReqxPyHLY44O rU/cQY1TfIBmM=; b=iKIz/yaWzi2o4cQ1jykMHF+FGl4hzGOVng0gYBTmhm55KG GKFLFNMRSEFynmdB+WfKyPGl+mPO56MXvH54ygUwmtVQv806Wr+STJdTEWiBIrFO hGhqeqVTAlSXYYzJqi/MR/dAaRjtrQBJlJfJtkdmONbAwmSwvDiRmZ/dVhEys=
- Feedback-id: i7af9444b:Fastmail
- Reply-to: Walt Mankowski <waltman@pobox.com>
- Sender: "plug" <plug-bounces@lists.phillylinux.org>
- User-agent: Cyrus-JMAP/3.9.0-alpha0-447-ge2460e13b3-fm-20230525.001-ge2460e13
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.
Walt
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
> simplest for GNU sed:
>
>
> Thanks,
> Aaron
>
>
> 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
> > file.
> >
> > 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?
> >
> > TIA!
> >
> > --
> > 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 --
> > Announcements -
> > 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