Reputation: 63
I want to delete:
,
.rdt(rdt)
from text:
.colldisn(1'b0),
.rdt(rdt)
while .colldisn
could be various texts.
So, I have a lot of file with this substring and I want to delete it.
Upvotes: 0
Views: 165
Reputation: 5347
myscript:
#!/usr/bin/perl -i.bak
undef $/; # get all the text
while(<>){
s/,\n\.rdt\(rdt\)//g;
print;
}
the "-i.bak" changes de original "file" but creates a "file.bak" copy. This way you can use
myscript *.txt
to change all txt files in current dir.
A similar switch exists for sed.
Upvotes: 0
Reputation: 384
sed -e ':a;N;$!ba;s/,\n.rdt(rdt)//g' tst.txt
Where the tst.txt
is you file, to write to the same file don't forget to add the -i
option.
The :a;N;$!ba;
will let you to accomplish what you want, witch is to compare several lines.
Upvotes: 2
Reputation: 58430
This might work for you (GNU sed):
sed '$!N;s/,\s*\n\s*\.rdt(rdt)//;P;D' file
If you want to preserve the space and newline:
sed '$!N;s/,\(\s*\n\s*\)\.rdt(rdt)/\1/;P;D' file
Upvotes: 2
Reputation: 241918
Should be easy in Perl: just keep the previous line in a variable. If you encounter .rdt(rdt)
, check that the previous line ends in a comma. If so, print the previous line without the comma and forget the current line, otherwise print the whole previous line. Do not forget to output the last line at the end of the file.
Upvotes: 0