Date: Wed, 26 Aug 2020 01:25:55 +0200 From: "Dr. Nikolaus Klepp" <dr.klepp@gmx.at> To: freebsd-questions@freebsd.org Subject: Re: Sed pattern help - not FreeBSD related Message-ID: <202008260125.55781.dr.klepp@gmx.at> In-Reply-To: <5f319e25-5eaf-1ae1-3695-9a1fcc01f9be@tundraware.com> References: <6B02E882-D3EE-4721-B572-BFAF5C6BAC66@kukulies.org> <81c68558-175c-efef-7e43-e6cb87f3329b@tundraware.com> <5f319e25-5eaf-1ae1-3695-9a1fcc01f9be@tundraware.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Anno domini 2020 Tue, 25 Aug 18:05:45 -0500
Tim Daneliuk scripsit:
> On 8/25/20 5:44 PM, Tim Daneliuk wrote:
> > On 8/25/20 4:02 PM, Christoph Kukulies wrote:
> >> Excuses, the result should look like: (forgot the DC)
> >>
> >>> LOOP: DC LOOP+2
> >>> DO: DC DO+2
> >>> J: DC J+2
> >>> ENCL: DC ENCL+2 PDP-11 VERSION OF ENCLOSE
> >>> KEY DC KEY+2
> >>> EMIT DC EMIT+2
> >>> QTERM DC QTERM+2
> >
> > Here is a one-liner using sed and awk. It suffers from two deficiencies:
> >
> > - It does not handle arbitrarily long comments
> > - It's really ugly
> >
> > sed s/':'//g < myfile | awk '{print $1":", $2, $1"+2", $4, $5, $6, $7, $8, $9. $10}'
> >
>
>
> Oops, not quite right because it inserts colons blindly in the first field -
> which appears not what you want. More correct implementation in Python:
>
> !/usr/bin/env python
>
> import sys
>
> for line in sys.stdin.readlines():
>
> line = line.strip().split()
> label = line[0]
> comment = " ".join(line[3:])
> print("%s DC %s+2 %s" %(label, label.replace(':', ''), comment))
>
>
>
sed 's#^\([^ \t]*\)\([^*]*\)[*]#\1\2\1#' <el2
nik
--
Please do not email me anything that you are not comfortable also sharing with the NSA, CIA ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008260125.55781.dr.klepp>
