Can anyone help me get this small sed script to work in shell on the command line?
I need it in a one liner really as i want to edit many scripts in a for loop and dont want to have to invoke a separate script each time.
#!/bin/sh
sed '/mailx\ -s.*$ {
i\
#Comment above mailx line
c\
mailx -s "blahblah blah my new subject" $someone_who_cares
}' $1
The script needs to match a pattern, insert a line above it and then change the pattern to something else.
I've tried the following and no joy
sed '/mailx\ -s.*$/ { i\ #Comment above mailx line c\ mailx -s "blahblah blah my new subject" $someone_who_cares }' file > file2
sed '/mailx\ -s.*$/ {; i\; #Comment above mailx line ;c\; mailx -s "blahblah blah my new subject" $someone_who_cares ;};' file > file2
i am reading the book <sed&awk>
here is a copy:
The append (a), insert (i), and change (c) commands provide editing functions that are commonly performed with an interactive editor, such as vi. You may find it strange to use these same commands to "enter" text using a noninteractive editor. The syntax of these commands is unusual for sed because they must be specified over multiple lines.