I have a file with thousands of lines. I’m looking for help to modify multiple lines which i were to choose.
Package: com.xyz.abc
Version: 1.0
Filename: ./debs/abc.deb
Package: com.xyz.def
Version: 1.0.0-1
Filename: ./debs/def.deb
I need a bash command to detect “Filename” then change them to something like this:
Package: com.xyz.abc
Version: 1.0
Filename: ./debs/download.php?p=abc
Package: com.xyz.def
Version: 1.0.0-1
Filename: ./debs/download.php?p=def
And it will loop till all “Filename” have been changed.
This is a job for
sed! From the GNU sed homepage:Here is how you could do it:
Where:
/^Filename:/looks for lines starting with (^) the text ‘Filename:’s!search!replace!replaces ‘search’ with ‘replace’ where ‘search’ is a regular expression\1is the string captured by the first matching group “\(...\)“\2is the string captured by the second matching group “\(...\)“Demonstration:
For tweaking this and for writing your own
sedscripts, please consult the online documentation.