3

I have a file with many lines and I would like to replace specific lines that start with a new line but include the old line in it. See below.

for example, if a line starts with (xyz is different for every line)

"#EXT-1,xyz"

I would like to have a line like this

!group=12, "#EXT-1,xyz", name="#EXT-1,xyz"

Is this possible to do with sed, and if so, how?

Zanna
  • 70,465
LewHam
  • 33

1 Answers1

6

There are a number of ways of formulating it - one would be

sed '/^\"#EXT-1,.*\"/ s//!group=12, &, name=&/' file

If you want to modify the file in place, then add the -i or --in-place switch

sed -i '/^\"#EXT-1,.*\"/ s//!group=12, &, name=&/' file
steeldriver
  • 136,215
  • 21
  • 243
  • 336