karthikraj karthikraj - 1 year ago 58
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]

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download