Issue
I have the following input file:
this is text
identifier {
item /directory/file_1234
some more text
item /directory/file_1234 other line text
identifier {
item /directory/98_76file
other line
I want to replace the stings item /directory/*
, that come after the line identifier {
with /directory/file_ABC
I tried
cat input | sed ':a;N;$!ba;s/ identifier {\n item \/directory\/.*$/ identifier {\n newitem \/directory2\/file_ABC/g'
but it erases the lines after the first occurrence
this is text
identifier {
newitem /directory2/file_ABC
Solution
Assuming you want to replace both occurances, you can use this sed
$ sed '/identifier {/{N;s~\(.*\n[^[:alpha:]]*\).*~\1newitem /directory/file_ABC~}' input_file
this is text
identifier {
newitem /directory/file_ABC
some more text
item /directory/file_1234 other line text
identifier {
newitem /directory/file_ABC
other line
Answered By - HatLess Answer Checked By - Mary Flores (WPSolving Volunteer)