Home > Back-end >  linux find and replace multiple times in file [closed]
linux find and replace multiple times in file [closed]

Time:10-05

I have a text-file containing serveral lines.

One or more lines contain something like

"SEARCHSTRING": "keep this data"

I want to transform my text-file in a way that every line of this type is transformed into two lines:

"result1": "keep this data"
"result2": "keep this data"

What is the best way to achieve that?

CodePudding user response:

Something like this sed command with backreferences:

sed 's/^"SEARCHSTRING"\(.*\)/"result1"\1\n"result2"\1/' infile
  • Related