insert the content between the matching pattern in shell script

I want to insert the content between the matching pattern in shell

For example :

file called input.txt :

var a = [ ]   

file called output.txt :

1152
1185
1185

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

That’s quite simple:

sed -i "s/[ ]/[$(cat output.txt | xargs)]/" input.txt

Leave a Reply

Your email address will not be published. Required fields are marked *