-2
[desktop ~]$ cat sa
sanmesh
shammas
sujil
givin
nepo
bijal

[desktop ~]$ sed -i -e '1i Header' -e '$a Trailor' sa

[desktop ~]$ cat sa
Header
sanmesh
shammas
sujil
givin
nepo
bijal
Trailor
  • 4
    have you tried searching in sed manual? Voting to close – RomanPerekhrest Dec 8 '17 at 11:48
3
sed -i -e '1i Header' -e '$a Trailor' sa

-i:

Edits the file in place

-e script:

Add the script to the commands to be executed

'1i Header':

Match 1st line ('1') and insert ('i') 'Header'

'$a Trailor':

Match last line ('$') and append ('a') 'Trailor' (but maybe you mean 'Trailer')

  • Can you please show an example case where -e is used effectively? – prado Dec 8 '17 at 13:07
  • 1
    -e is used effectively in this example – PiedPiper Dec 8 '17 at 13:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.