syedasadali95 has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks, I am trying to search and replace a desired portion from a line using perl but not able to match regex to the end of a word. let me explain the issue below
Line:
0 (0) tracegen chn:req cmd:SDP_CMD_RDSIZED unit:0x10 addr:0x0 len:0x3f + vc:0 qospri:0 qosfw:0 strm:0x0 chain:0 io:0
Code:
$line1 =~ s/addr\:0x.*\S/addr\:$address/;
Result:
0 (0) tracegen chn:req cmd:SDP_CMD_RDSIZED unit:0x10 addr:0x500000000
Unfortunately my code is trimming the rest of the line after addr field which shouldn't happen.
expected result:
0 (0) tracegen chn:req cmd:SDP_CMD_RDSIZED unit:0x10 addr:0x500000000 +len:0x3f vc:0 qospri:0 qosfw:0 strm:0x0 chain:0 io:0
Please suggest a solution to match next white space after addr field or to match end of string and replace. I've tried $, \s, \S, \z, \', etc. But doesn't worked well
2019-05-30 Athanasius added code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: search and replace desired portion from a line
by Eily (Monsignor) on May 29, 2019 at 07:58 UTC | |
by syedasadali95 (Acolyte) on May 30, 2019 at 07:01 UTC | |
|
Re: search and replace desired portion from a line (updated)
by AnomalousMonk (Archbishop) on May 29, 2019 at 15:44 UTC | |
by syedasadali95 (Acolyte) on May 30, 2019 at 07:04 UTC | |
|
Re: search and replace desired portion from a line
by thanos1983 (Parson) on May 29, 2019 at 08:42 UTC | |
by syedasadali95 (Acolyte) on May 30, 2019 at 07:03 UTC |