I'm using GNU sed 4.7 on Debian 11.
I have a file with many lines, all of which have a first string in curly brackets at the beginning of the line, a final string in @
chars at the end of the line, and a string containing alphanumeric, punctuation and other charcaters between the aforementioned termini strings.
I want to generate output showing the first and last strings in their entirity, and ONLY the non-alphanum chars from the middle string, thus:
./file
contains the following:
{string-no1}middle@string-no2@
{AAAAAAAAAA}1,a.B£@ZZZZZZZZZZ@
{GGGGGGGGGG}&:3m?J@@@@@@@@@@@@
... and I would like to see output:
{string-no1}@string-no2@
{AAAAAAAAAA},.£@ZZZZZZZZZZ@
{GGGGGGGGGG}&:?@@@@@@@@@@@@
I tried:
sed 's/\({[^}]*}\)[^a-zA-Z0-9]*\(@[^@]*@\)/\1\2/' ./file
...but that doesn't work, and neither does:
sed 's/\({[^}]*}\)[[:punct:]]*\(@[^@]*@\)/\1\2/' ./file`
...nor does:
sed '/}/,/@/ s/[a-zA-Z0-9]*//' ./file
I've tried finding help with grymoire, and on StackExchange too, which usually solves anything, but this one's really got me foxed. Can anybody help?
@
characters flanked by a single@
on either side. (@[^@]*@
does not match the entire length of@@@@@@@@@@@@
). It doesn't make difference for the outcome, but it is unexpected.