bash - insert single quote with sed -
i want add text on line:
sudo sed -i '5imytext 16/16' /file
now i've added mytext 16/16
on line 5 of file want add text 'mytext' 16/16
(mytext between single quotes)
i tried
sudo sed -i '5i'mytext' 16/16' /file
but didn't work. can me?
the single quotes you're trying use in insertion string interfering ones around sed command.
the simplest thing use different quotes around sed command:
"5i'mytext' 16/16"
normally it's best use single quotes around sed command more tricky in case:
'5i'"'"'mytext'"'"' 16/16'
basically, need put single quotes inside double quotes somehow , in case there's no reason not double quote whole command.
as suggested 123 in comments, alternative put sed command script file:
5i'mytext' 16/16
then use -f
switch sed:
sed -f script
this avoids need use 2 kinds of quotes.
Comments
Post a Comment