Bash replace multiple lines in a file between two patterns with the content of another file?
0
votes
2
answers
1689
views
I have a long javascript file `
long.js
` which has this content as a part of it
... more lines
ProcessCoverageController.createExampleQueries = function () {
return [
{
title: '-- Select a query --',
query: ''
}, {
title: 'No encoding',
query: 'return avg($c)'
}
];
};
ProcessCoverageController.$inject = [
"$scope",
"$log",
"$interval",
"Notification",
"rasdaman.WCSService",
"rasdaman.ErrorHandlingService"
];
... more lines
What I want to do is to replace the content of return [ ... ];
with the content from another file (e.g: `content.js
`) which has this content:
return [
{
title: 'title1',
query: query1 as asdasd asdasd
}, {
title: 'title2',
query: query2 asdas dasd asd asda
}, {
title: 'title3',
query: query3 asd asdasdasdasdasdasdasd
}, {
title: 'title4',
query: query4 3asd asdasda sdasdasdasdasdad
}
];
Can someone give me a hint how to do that with sed or perl (I've tried to look at that, and it seems perl is an easier tool to do then sed). This example below doesn't work properly though:
#!/bin/bash
file_content=cat content.js
perl -i -p0e 's/ProcessCoverageController.createExampleQueries = function.*?ProcessCoverageController.\$inject/$file_content/s' long.js
Asked by Bằng Rikimaru
(195 rep)
Jan 12, 2021, 03:20 PM
Last activity: Oct 22, 2024, 06:53 AM
Last activity: Oct 22, 2024, 06:53 AM