Trying to avoid a perl script which wouldn't be hard, but I am looking
for an awk one liner that does a replacement, but only after it sees a
key word on some line.
Anyone know of that's easy to do?
{if ( $0 ~ /keyword/) (sub(str, repl);} print $0;}
mark
Depends on how you define one-liner. Something like this might work:
{ if index($0, PATTERN) != 0 {FOUND = 1;}; if (FOUND != 0)
{subst(REPLACE_THIS, WITH_THIS, $0); }
You'd want to reverse the order of the two statements if the
replacement is only to occur after the pattern is found.
Cool,
or do you mean
blah, blah
blah, blah
yadda, yadda, keyword,
to-be-replaced
also-to-be-replaced?
Yup, the keyword marks the position where I then start looking
for matches. Once I get to work, I will give these a try.
Thanks guys!
jlc
___
CentOS mailing
or do you mean
blah, blah
blah, blah
yadda, yadda, keyword,
to-be-replaced
also-to-be-replaced?
Yup, the keyword marks the position where I then start looking
for matches. Once I get to work, I will give these a try.
Thanks guys!
Sure. And what you want is just
{ if ($0 ~ /keyword/ ) {
On Fri, Mar 26, 2010 at 7:28 AM, m.r...@5-cent.us wrote:
or do you mean
blah, blah
blah, blah
yadda, yadda, keyword,
to-be-replaced
also-to-be-replaced?
Yup, the keyword marks the position where I then start looking
for matches. Once I get to work, I will give these a try.
Thanks guys!
or do you mean
blah, blah
blah,
blah
yadda, yadda,
keyword,
to-be-replaced
also-to-be-replaced?
Yup, the keyword marks the position where I then start looking
for
matches. Once I get to work, I will give these a try.
Thanks
guys!
Sure. And what you want is just
{ if ($0 ~
Trying to avoid a perl script which wouldn't be hard, but I am looking
for an awk one liner that does a replacement, but only after it sees a
key word on some line.
Anyone know of that's easy to do?
Thanks!
jlc
___
CentOS mailing list
CentOS@centos.org
On Fri, 2010-03-26 at 00:36 +, Joseph L. Casale wrote:
Trying to avoid a perl script which wouldn't be hard, but I am looking
for an awk one liner that does a replacement, but only after it sees a
key word on some line.
Anyone know of that's easy to do?
Thanks!
sounds more like a
sounds more like a reason to use sed
man sed or tell us exactly what you are trying to do
Tell you the truth, I would much rather use sed, but I didn't think
that was doable with it.
I have a slew of txt files that contain a keyword like service-one
on many lines. I need to change those, but
Joseph L. Casale wrote:
sounds more like a reason to use sed
man sed or tell us exactly what you are trying to do
Tell you the truth, I would much rather use sed, but I didn't think
that was doable with it.
I have a slew of txt files that contain a keyword like service-one
on many
Can you use a regexp like:
s/\(known_part\)\(.*\)\(change_part\)/\1\2replace_part/
Unless I misunderstand that, I'd say no.
The actual file might look this:
/begin file
foo bar{
biz service-one
baz service-two
}
--many more of that--
# comment
fiz bir{
aaa
Joseph L. Casale wrote:
Can you use a regexp like:
s/\(known_part\)\(.*\)\(change_part\)/\1\2replace_part/
Unless I misunderstand that, I'd say no.
The actual file might look this:
/begin file
foo bar{
biz service-one
baz service-two
}
--many more of that--
I think there is a way to do it in sed using the holding space, but it's so
much
easier in perl that I never bothered to learn the hard parts. What's the
problem with using perl anyway?
No problem, just thought there was a sexier way to do it then my ugly way. The
Perl solution would be just
Depends on how you define one-liner. Something like this might work:
{ if index($0, PATTERN) != 0 {FOUND = 1;}; if (FOUND != 0)
{subst(REPLACE_THIS, WITH_THIS, $0); }
You'd want to reverse the order of the two statements if the
replacement is only to occur after the pattern is found.
Cool,
On 03/26/2010 02:02 PM, Joseph L. Casale wrote:
I think there is a way to do it in sed using the holding space, but it's so
much
easier in perl that I never bothered to learn the hard parts. What's the
problem with using perl anyway?
No problem, just thought there was a sexier way to do
15 matches
Mail list logo