replace words depend on second line [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a netlist file. I has splited lines. The split sign is '+' at the beginning of one line.
MP1 Y A VDD VDD pch_25 W=1u L=550n M=1
MP0 Y B
+VDD VDD pch_25 W=1u L=550n M=1
MN1 v0 A VSS VSS nch_25_dnw W=500.0n L=550n M=1
MN0 Y B v0 VSS nch_25_dnw W=500.0n L=550n M=1
I'd like to replace the beginning M of each line with X if that line contain pch_25. I have the following command:
sed -e :a -e '$!N;s/n+/\/;ta' -e 'P;D' file | sed '/pch_25/s/^M/X/' | sed -e 's/\/n+/g'
How to replace this command with a single sed
without pipeline?
sed
closed as unclear what you're asking by ñÃÂsýù÷, maulinglawns, John, dhag, roaima Jan 5 at 22:25
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |Â
up vote
1
down vote
favorite
I have a netlist file. I has splited lines. The split sign is '+' at the beginning of one line.
MP1 Y A VDD VDD pch_25 W=1u L=550n M=1
MP0 Y B
+VDD VDD pch_25 W=1u L=550n M=1
MN1 v0 A VSS VSS nch_25_dnw W=500.0n L=550n M=1
MN0 Y B v0 VSS nch_25_dnw W=500.0n L=550n M=1
I'd like to replace the beginning M of each line with X if that line contain pch_25. I have the following command:
sed -e :a -e '$!N;s/n+/\/;ta' -e 'P;D' file | sed '/pch_25/s/^M/X/' | sed -e 's/\/n+/g'
How to replace this command with a single sed
without pipeline?
sed
closed as unclear what you're asking by ñÃÂsýù÷, maulinglawns, John, dhag, roaima Jan 5 at 22:25
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
4
post the expected result
â RomanPerekhrest
Jan 5 at 14:39
If it works, what's wrong with having a pipeline?
â roaima
Jan 5 at 22:24
I aim to write a sed scrpit. I have an other shell script which call the sed script.
â spectre
Jan 6 at 2:23
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a netlist file. I has splited lines. The split sign is '+' at the beginning of one line.
MP1 Y A VDD VDD pch_25 W=1u L=550n M=1
MP0 Y B
+VDD VDD pch_25 W=1u L=550n M=1
MN1 v0 A VSS VSS nch_25_dnw W=500.0n L=550n M=1
MN0 Y B v0 VSS nch_25_dnw W=500.0n L=550n M=1
I'd like to replace the beginning M of each line with X if that line contain pch_25. I have the following command:
sed -e :a -e '$!N;s/n+/\/;ta' -e 'P;D' file | sed '/pch_25/s/^M/X/' | sed -e 's/\/n+/g'
How to replace this command with a single sed
without pipeline?
sed
I have a netlist file. I has splited lines. The split sign is '+' at the beginning of one line.
MP1 Y A VDD VDD pch_25 W=1u L=550n M=1
MP0 Y B
+VDD VDD pch_25 W=1u L=550n M=1
MN1 v0 A VSS VSS nch_25_dnw W=500.0n L=550n M=1
MN0 Y B v0 VSS nch_25_dnw W=500.0n L=550n M=1
I'd like to replace the beginning M of each line with X if that line contain pch_25. I have the following command:
sed -e :a -e '$!N;s/n+/\/;ta' -e 'P;D' file | sed '/pch_25/s/^M/X/' | sed -e 's/\/n+/g'
How to replace this command with a single sed
without pipeline?
sed
edited Jan 5 at 14:35
Philippos
5,90211545
5,90211545
asked Jan 5 at 14:32
spectre
91
91
closed as unclear what you're asking by ñÃÂsýù÷, maulinglawns, John, dhag, roaima Jan 5 at 22:25
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by ñÃÂsýù÷, maulinglawns, John, dhag, roaima Jan 5 at 22:25
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
4
post the expected result
â RomanPerekhrest
Jan 5 at 14:39
If it works, what's wrong with having a pipeline?
â roaima
Jan 5 at 22:24
I aim to write a sed scrpit. I have an other shell script which call the sed script.
â spectre
Jan 6 at 2:23
add a comment |Â
4
post the expected result
â RomanPerekhrest
Jan 5 at 14:39
If it works, what's wrong with having a pipeline?
â roaima
Jan 5 at 22:24
I aim to write a sed scrpit. I have an other shell script which call the sed script.
â spectre
Jan 6 at 2:23
4
4
post the expected result
â RomanPerekhrest
Jan 5 at 14:39
post the expected result
â RomanPerekhrest
Jan 5 at 14:39
If it works, what's wrong with having a pipeline?
â roaima
Jan 5 at 22:24
If it works, what's wrong with having a pipeline?
â roaima
Jan 5 at 22:24
I aim to write a sed scrpit. I have an other shell script which call the sed script.
â spectre
Jan 6 at 2:23
I aim to write a sed scrpit. I have an other shell script which call the sed script.
â spectre
Jan 6 at 2:23
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Obviously the format allows multiple line breaks, so the N;P;D
pattern doesn't fit here really good: If you collect more lines, you need to print and remove all but one, but P;D
doesn't do that, that's why you do the replacing stuff.
Here is the first way I can think of:
sed -e :a -e '$be' -e 'N;/n[^+]/!ba' -e :e -e 'h;s/n[^+].*//;/pch_25/s/^M/X/;p;g;/n[^+]/!d;s/.*n//;ba' file
We loop to collect lines until we hit the last line or a line not starting with +
. Then save the pattern in the hold space and remove the last line from the space, if it's not starting with +
. Now all lines that form one record are together in the pattern space; we can do the desired replacement and print it.
Now the g
gets back the pattern before removing the beginning of the next record. If it doesn't contain a newline followed by a non-+
, it's been the last record and we can d
elete it and exit. Otherwise remove everything but the last line and go back to mark :a
.
(Note that you can't simply use s/.*n([^+])/1/;ta
, because the t
could be triggered by an earlier s
replacement.)
Update: Alternative dirty trick to use N;P;D
anyhow:
sed -e '/^end$/d;/^+/P;D;;:a' -e '$x;s/.*/end/;H;x;;$!N;/n[^+]/!ba' -e '/pch_25.*n/s/^M/X/;P;D' file
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Obviously the format allows multiple line breaks, so the N;P;D
pattern doesn't fit here really good: If you collect more lines, you need to print and remove all but one, but P;D
doesn't do that, that's why you do the replacing stuff.
Here is the first way I can think of:
sed -e :a -e '$be' -e 'N;/n[^+]/!ba' -e :e -e 'h;s/n[^+].*//;/pch_25/s/^M/X/;p;g;/n[^+]/!d;s/.*n//;ba' file
We loop to collect lines until we hit the last line or a line not starting with +
. Then save the pattern in the hold space and remove the last line from the space, if it's not starting with +
. Now all lines that form one record are together in the pattern space; we can do the desired replacement and print it.
Now the g
gets back the pattern before removing the beginning of the next record. If it doesn't contain a newline followed by a non-+
, it's been the last record and we can d
elete it and exit. Otherwise remove everything but the last line and go back to mark :a
.
(Note that you can't simply use s/.*n([^+])/1/;ta
, because the t
could be triggered by an earlier s
replacement.)
Update: Alternative dirty trick to use N;P;D
anyhow:
sed -e '/^end$/d;/^+/P;D;;:a' -e '$x;s/.*/end/;H;x;;$!N;/n[^+]/!ba' -e '/pch_25.*n/s/^M/X/;P;D' file
add a comment |Â
up vote
0
down vote
Obviously the format allows multiple line breaks, so the N;P;D
pattern doesn't fit here really good: If you collect more lines, you need to print and remove all but one, but P;D
doesn't do that, that's why you do the replacing stuff.
Here is the first way I can think of:
sed -e :a -e '$be' -e 'N;/n[^+]/!ba' -e :e -e 'h;s/n[^+].*//;/pch_25/s/^M/X/;p;g;/n[^+]/!d;s/.*n//;ba' file
We loop to collect lines until we hit the last line or a line not starting with +
. Then save the pattern in the hold space and remove the last line from the space, if it's not starting with +
. Now all lines that form one record are together in the pattern space; we can do the desired replacement and print it.
Now the g
gets back the pattern before removing the beginning of the next record. If it doesn't contain a newline followed by a non-+
, it's been the last record and we can d
elete it and exit. Otherwise remove everything but the last line and go back to mark :a
.
(Note that you can't simply use s/.*n([^+])/1/;ta
, because the t
could be triggered by an earlier s
replacement.)
Update: Alternative dirty trick to use N;P;D
anyhow:
sed -e '/^end$/d;/^+/P;D;;:a' -e '$x;s/.*/end/;H;x;;$!N;/n[^+]/!ba' -e '/pch_25.*n/s/^M/X/;P;D' file
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Obviously the format allows multiple line breaks, so the N;P;D
pattern doesn't fit here really good: If you collect more lines, you need to print and remove all but one, but P;D
doesn't do that, that's why you do the replacing stuff.
Here is the first way I can think of:
sed -e :a -e '$be' -e 'N;/n[^+]/!ba' -e :e -e 'h;s/n[^+].*//;/pch_25/s/^M/X/;p;g;/n[^+]/!d;s/.*n//;ba' file
We loop to collect lines until we hit the last line or a line not starting with +
. Then save the pattern in the hold space and remove the last line from the space, if it's not starting with +
. Now all lines that form one record are together in the pattern space; we can do the desired replacement and print it.
Now the g
gets back the pattern before removing the beginning of the next record. If it doesn't contain a newline followed by a non-+
, it's been the last record and we can d
elete it and exit. Otherwise remove everything but the last line and go back to mark :a
.
(Note that you can't simply use s/.*n([^+])/1/;ta
, because the t
could be triggered by an earlier s
replacement.)
Update: Alternative dirty trick to use N;P;D
anyhow:
sed -e '/^end$/d;/^+/P;D;;:a' -e '$x;s/.*/end/;H;x;;$!N;/n[^+]/!ba' -e '/pch_25.*n/s/^M/X/;P;D' file
Obviously the format allows multiple line breaks, so the N;P;D
pattern doesn't fit here really good: If you collect more lines, you need to print and remove all but one, but P;D
doesn't do that, that's why you do the replacing stuff.
Here is the first way I can think of:
sed -e :a -e '$be' -e 'N;/n[^+]/!ba' -e :e -e 'h;s/n[^+].*//;/pch_25/s/^M/X/;p;g;/n[^+]/!d;s/.*n//;ba' file
We loop to collect lines until we hit the last line or a line not starting with +
. Then save the pattern in the hold space and remove the last line from the space, if it's not starting with +
. Now all lines that form one record are together in the pattern space; we can do the desired replacement and print it.
Now the g
gets back the pattern before removing the beginning of the next record. If it doesn't contain a newline followed by a non-+
, it's been the last record and we can d
elete it and exit. Otherwise remove everything but the last line and go back to mark :a
.
(Note that you can't simply use s/.*n([^+])/1/;ta
, because the t
could be triggered by an earlier s
replacement.)
Update: Alternative dirty trick to use N;P;D
anyhow:
sed -e '/^end$/d;/^+/P;D;;:a' -e '$x;s/.*/end/;H;x;;$!N;/n[^+]/!ba' -e '/pch_25.*n/s/^M/X/;P;D' file
edited Jan 5 at 15:32
answered Jan 5 at 15:04
Philippos
5,90211545
5,90211545
add a comment |Â
add a comment |Â
4
post the expected result
â RomanPerekhrest
Jan 5 at 14:39
If it works, what's wrong with having a pipeline?
â roaima
Jan 5 at 22:24
I aim to write a sed scrpit. I have an other shell script which call the sed script.
â spectre
Jan 6 at 2:23