Sed pattern help - not FreeBSD related

Christoph Kukulies kuku at kukulies.org
Wed Aug 26 07:57:38 UTC 2020


my solution:

$ sed  's/^\([A-Z0-9]*\)\(:*\)\([[:space:]]*\)\(DC[[:space:]]*[*][+]2\)/\1\2\3DC \1+2/' <el2
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



Thanks for helping.

—
Christoph


> Am 26.08.2020 um 09:04 schrieb Christoph Kukulies <kuku at kukulies.org>:
> 
> 
> 
>> Am 26.08.2020 um 01:46 schrieb Tim Daneliuk <tundra at tundraware.com>:
>> 
>> On 8/25/20 6:25 PM, Dr. Nikolaus Klepp wrote:
>>> 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
>>> 
>>> 
> 
> 
> My problem was that BSD sed doesn’t recognize [ \t] as white space. GNU sed does.
> 
> I was trying the command under FreeBSD sed and macOS sed.
> 
>>> nik
>>> 
>>> 
>>> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3363 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20200826/14bb0b92/attachment.bin>


More information about the freebsd-questions mailing list