I have a file that looks like this:
bar
barfo
barfoo
barfooo
barfoooo
sample
sampleText1
sampleText2
sampleText3
prefix
prefixFooBar
prefixBarFoo
What I want sed (or awk) to do is to remove the string which introduces a section, from all of its contents, so that I end up with:
bar
fo
foo
fooo
foooo
sample
Text1
Text2
Text3
prefix
FooBar
BarFoo
I tried using
sed -e -i '/([[:alpha:]]+)/,/^$/ s/\1//g' file
But that fails with "Invalid Backreference".
$ awk '{$0=substr($0,idx)} !idx{idx=length($0)+1} !NF{idx=0} 1' file
bar
fo
foo
fooo
foooo
sample
Text1
Text2
Text3
prefix
FooBar
BarFoo
another awk
$ awk '{sub(pre,"")}1; !NF{pre=""} !pre{pre=$1}' file
bar
fo
foo
fooo
foooo
sample
Text1
Text2
Text3
prefix
FooBar
BarFoo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With