Tolgar
asked on
How to replace a string in Perl for the given string?
file://///dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/dir11/dir12/20120816_1331_ReportDetails.html#/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/dir11/dir12/file.c
How can I replace the html file name in the string given above as the below:
file://///dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/dir11/dir12/Test1_ReportDetails.html#/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/dir11/dir12/file.c
Try:
s#[^/]+_(ReportDetails.html)#Test1_$1#g
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Original and replace are variables in my code. So I replaced single quotes with double quotes.
This is my line of code:
But got this error:
This is my line of code:
sed "s/$reportFileDetailsName/$newReportFileDetailsName/g" $reportFileName;
But got this error:
String found where operator expected at test.t line 225, near "sed "s/$reportFileDetailsName/$newReportFileDetailsName/g""
(Do you need to predeclare sed?)
Scalar found where operator expected at test.t line 225, near ""s/$reportFileDetailsName/$newReportFileDetailsName/g" $reportFileName"
(Missing operator before $reportFileName?)
syntax error at test.t line 225, near "sed "s/$reportFileDetailsName/$newReportFileDetailsName/g""
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In filename.txt file put the above text.
Open in new window