0

I am using these two sed expressions piped together

sed -e "1 i\MODEL" file.txt | sed -e 's/END/ENDMDL/g' > output.txt

to 1) add "MODEL" on the first line of text.txt and then to substitute END with the ENDMDL within the same file.

How it would be possible make the both actions by means of one SED command (thus avoiding pipe) not producing a new file but rather to substitute existing one ? Finally I would like to know how it would be possible to add something on the last line of the file?

user3470313
  • 303
  • 5
  • 16

1 Answers1

2

You can specify multiple commands either by using multiple occurences of the -e <command> option or by joining them with ; :

sed -e "1 i\MODEL" -e 's/END/ENDMDL/g' file.txt
sed -e '1 i\MODEL;s/END/ENDMDL/g' file.txt

You can specify the end row using $ :

sed -e "$ i\ENDMODEL" file.txt
Aaron
  • 24,009
  • 2
  • 33
  • 57