insert the content between the matching pattern in shell script Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of insert the content between the matching pattern in shell script without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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

We are here to answer your question about insert the content between the matching pattern in shell script - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji