SED - insert space at the beginning of line and multi replace command

hi I am trying to use SED to replace the line matching a pattern using the command

 
sed 'pattern c\
new line
' <file1 >file 2

I got two questions

  1. how do I insert a blank space at the beginning of new line?

  2. how do I use this command to execute multiple command using the -e options (if possible)? as I want to replace multiple lines in a single file.

Thanks
Robert

Could you please provide an example of what input you have and what output you expect, people may then be able to provide more accurate suggestions.
Thanks

... by the way, at the beginning of which lines would you like to insert a space ? all ? only some ? which ?

for example

file1 contain this line

 
 name/date/record/serial (note a single space at beginning of line)

and I am using the sed command

sed 'name c\
name/date/record/$newserial
' <file1 >file2
 

to change the line with variable $newserial

Problem is it won't keep the space at the beginning of the line, and I want to keep it (for tidy sake).

Secondly I want to do multiple change in a single file but dont' know how to combine the c\ with the -e command in SED, so that I won't have to write multiple SED command in the script which would require to generate a new output file everytime the SED c\ command is called.

hope that clear things up.

Thanks

Just put a space before the new text and it will be preserved (the bolded, red underscore is where the space would go):

sed '
/pattern1/ c\
_newtext1
/pattern2/ c\
_newtext2
' file

On an unrelated note, if you want to expand the value of a shell variable into the new text, you cannot use single quotes; you must use double quotes instead.

Regards,
Alister

I tried it but it doesn't work.....

Which shell and operating system are you using? Post the exact code that you tried in the exact way that you invoked it. Post the exact erroneous output and error message that you received. Otherwise, we can't be of any help.

Regards,
Alister