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?
1 Answer
There are a number of ways of formulating it - one would be
sed '/^\"#EXT-1,.*\"/ s//!group=12, &, name=&/' fileIf 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 3