Skip to main content
Post Closed as "Duplicate" by don_crissti, Jeff Schaller, CommunityBot, RalfFriedl, Romeo Ninov
fixed formatting
Source Link
Daniele Santi
  • 4.2k
  • 2
  • 32
  • 30

I want to replace create_testcreate_test in the file with #create_test#create_test if the next line contains psfxxx_16_pipsfxxx_16_pi. How can I do it with sed for the whole file containing this?

Input file content:

"create_test -type hard -outer { 1.0000 } {
psfxxx_16_pi/psfop/deadline_north_re_0 }

create_test -type hard -outer { 0.0000 } {
psfxxx_16_pi/psfop/deadline_south_re_1 }"

create_test -type hard -outer { 1.0000 } { \ psfxxx_16_pi/psfop/deadline_north_re_0 } create_test -type hard -outer { 0.0000 } { \ psfxxx_16_pi/psfop/deadline_south_re_1 } 

Output file:

"#create_test -type hard -outer { 1.0000 } {
psfxxx_16_pi/psfop/deadline_north_re_0 }

#create_test -type hard -outer { 0.0000 } {
psfxxx_16_pi/psfop/deadline_south_re_1 }"

#create_test -type hard -outer { 1.0000 } { \ psfxxx_16_pi/psfop/deadline_north_re_0 } #create_test -type hard -outer { 0.0000 } { \ psfxxx_16_pi/psfop/deadline_south_re_1 } 

I want to replace create_test in the file with #create_test if the next line contains psfxxx_16_pi. How can I do it with sed for the whole file containing this?

Input file content:

"create_test -type hard -outer { 1.0000 } {
psfxxx_16_pi/psfop/deadline_north_re_0 }

create_test -type hard -outer { 0.0000 } {
psfxxx_16_pi/psfop/deadline_south_re_1 }"

Output file:

"#create_test -type hard -outer { 1.0000 } {
psfxxx_16_pi/psfop/deadline_north_re_0 }

#create_test -type hard -outer { 0.0000 } {
psfxxx_16_pi/psfop/deadline_south_re_1 }"

I want to replace create_test in the file with #create_test if the next line contains psfxxx_16_pi. How can I do it with sed for the whole file containing this?

Input file content:

create_test -type hard -outer { 1.0000 } { \ psfxxx_16_pi/psfop/deadline_north_re_0 } create_test -type hard -outer { 0.0000 } { \ psfxxx_16_pi/psfop/deadline_south_re_1 } 

Output file:

#create_test -type hard -outer { 1.0000 } { \ psfxxx_16_pi/psfop/deadline_north_re_0 } #create_test -type hard -outer { 0.0000 } { \ psfxxx_16_pi/psfop/deadline_south_re_1 } 
Source Link

sed: replace part of text in previous line if match is found

I want to replace create_test in the file with #create_test if the next line contains psfxxx_16_pi. How can I do it with sed for the whole file containing this?

Input file content:

"create_test -type hard -outer { 1.0000 } {
psfxxx_16_pi/psfop/deadline_north_re_0 }

create_test -type hard -outer { 0.0000 } {
psfxxx_16_pi/psfop/deadline_south_re_1 }"

Output file:

"#create_test -type hard -outer { 1.0000 } {
psfxxx_16_pi/psfop/deadline_north_re_0 }

#create_test -type hard -outer { 0.0000 } {
psfxxx_16_pi/psfop/deadline_south_re_1 }"