0
votes

I tried executing sed command in my script to insert a text above another line, whenever I come across my search pattern. I tried the 'a' command to insert the text but I couldn't get it to work.

sed '/Splitter/a \ "help" '  fileList.out

sed: 1: "/Splitter/a \ "help" ": extra characters after \ at the end of a command

machine-1:Splitter machine-1$ sed '/Splitter  /"help" /a \ '  fileList.out 

sed: 1: "/Splitter /"help" /a \ ": invalid command code "

machine-1:Splitter machine-1$ sed '/Splitter  /"help" a \ '  fileList.out 

sed: 1: "/Splitter /"help" a \ ": invalid command code "

machine-1:Splitter machine-1$ sed '/Splitter/"help"/a \ '  fileList.out 

sed: 1: "/Splitter/"help"/a \ ": invalid command code "

machine-1:Splitter machine-1$ sed '/Splitter/help/a \ '  fileList.out 

sed: 1: "/Splitter/help/a \ ": extra characters at the end of h command

machine-1:Splitter machine-1$ sed '/Splitter/a \ '  fileList.out 

//File List

./Splitter/View

./Splitter/App

./Splitter/Util

./Splitter/main

./Splitter/Check/SplitImage

./SplitterTests/SplitterTests

./Splitter/SplitterITests

 machine-1:Splitter machine-1$ sed '/Splitter/a \ '  fileList.out 
2

2 Answers

1
votes

The a command expects a \ followed by a newline, then followed by text.

So the command should be:

sed '/Splitter/a\
"help"'

See also the sed man page.

0
votes

To insert your text above the matching line, use the i command :

sed '/Splitter/i \
"help"
' fileList.out