I have the following codes for a project that I'm already done writing the sed commands for it.
sed -i '/^[[:space:]]*$/d' letter.txt
sed -i -e '4 s/([^()]*) */800-/' letter.txt
sed -i '/;/s/\(.\)\(.\)\(.\)\(.\) *$/\4\3\2\1/' letter.txt
sed -i '14 s/Lane/Kent/' letter.txt
sed -i 's/Lane/Ln/' letter.txt
sed -i '12 s/654/\n/g;s/817/654/g;s/\n/817/g' letter.txt
sed -i "$ a p.s. your winnings must be claimed by February 29th. " letter.txt
sed -i '4s/$/\n/;5s/$/\n/;9s/$/\n\n/;10s/$/\n/;12s/$/\n/' letter.txt
The commands work just fine when I enter them one by one into the console, but the instructors need us to make a .sed file and run all of them through there.
This is what I have inside my .sed
file so far:
/^[[:space:]]*$/d
4 s/([^()]*) */800-/
/;/s/\(.\)\(.\)\(.\)\(.\) *$/\4\3\2\1/
14 s/Lane/Kent/
s/Lane/Ln/
12 s/654/\n/g;s/817/654/g;s/\n/817/g
$ a p.s. your winnings must be claimed by February 29th.
4s/$/\n/;5s/$/\n/;9s/$/\n\n/;10s/$/\n/;12s/$/\n/
I run it using sed -r -E -f minor1.sed letter.txt
and I get the following error in console:
sed: file minor1.sed line 4: invalid reference \4 on `s' command's RHS
Any help would appreciated!
sed
today and this is clearly some kind of homework, I'd suggest at least trying to study on your own. – BulletBob Feb 10 '21 at 23:04-r
(and , superfluously,-E
), which affects the interpretation of\(
and\)
. See for example Why does my regular expression work in X but not in Y? – steeldriver Feb 10 '21 at 23:07