1752577 Members
5406 Online
108788 Solutions
New Discussion юеВ

Re: A few sed questions

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: A few sed questions

Hi (again) Gemini:

> Dennis: You are missing the last line

Oops, yes, indeed! Add to the Perl script, too:

END{print $hold}'

# perl -nle 'if (/^ifeq/) {$hold=~s/install/NEWINSTALL/};print $hold if defined $hold;$hold=$_;END{print $hold}' file

# awk '{if (/^ifeq/) {sub("install","NEWINSTALL",hold)};if (NR>1) print hold};hold=$0};END{print hold}' file

Regards!

...JRF...
Gemini_2
Regular Advisor

Re: A few sed questions

thanks you for your kind help!

both of you!

Dennis Handly
Acclaimed Contributor

Re: A few sed questions

You can also remove the check for NR > 1 by using BEGIN:
awk '
BEGIN {hold=$0}
{
if (/^ifeq/) {
sub("install","NEWINSTALL",hold)
}
print hold
hold=$0
}
END {print hold}' file
James R. Ferguson
Acclaimed Contributor

Re: A few sed questions

Hi (again) Gemini:

> Dennis: You can also remove the check for NR > 1 by using BEGIN

Yes, and similarly, in my Perl code I could do:

# perl -ne 'INIT{$hold=<>};if (/^ifeq/) {$hold=~s/install/NEWINSTALL/};print $hold;$hold=$_;END{print $hold}' file

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: A few sed questions

Hi Gemini:

All right, here's a 'sed' script for you question of August 13:

# cat sedfilter
#!/usr/bin/sed -nf
h;N
/ifeq/ {H;s/install/NEWINSTALL/;p;}
/ifeq/!p

...run as:

# sedfilter file

Regards!

...JRF...
Gemini_2
Regular Advisor

Re: A few sed questions

impressive!

you are the script guru!

thanks a lot!