karthikraj karthikraj - 9 months ago 17
Bash Question

insert the content between matching pattern in unix

I want to insert the content between the matching pattern in shell please help on this

For example :

file called input.txt :

var a = [ ]

file called output.txt :


I want to insert the values from output.txt file to the file input.txt.
it should be like var a = [1152 1185 1185]

sed "s/\[/[ $(xargs < output.txt)/" input.txt

xargs < filename dumps all file lines in just one, i.e., replaces EOL characters for SPACE characters.

$(xargs < filename) expands to the contents of the filename in just one line. Hence the use of double quotes, not single ones.