LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find and replace the column in perl (https://www.linuxquestions.org/questions/linux-newbie-8/find-and-replace-the-column-in-perl-4175615799/)

spatil20 10-17-2017 12:37 AM

Find and replace the column in perl
 
Simple requirement need to find the string A.FIND_REPLCAE column in <SQL>,</SQL> and replcae with trim(A.FIND_REPLCAE) in <SQL> </SQL> in XML.txt file as given below example

Input(evey time line numbers will change)
this is @12th line <SQL><SelectStatement modified=\\'1\\' type=\\'string\\'><![CDATA[
SEL A.COLUMN_NMAE1,
A.FIND_REPLCAE
FROM TABLE_NAME
\><Tables collapsed=\\'1\\'></Tables><Parameters collapsed=\\'1\\'></Parameters><Columns collapsed=\\'1\\'></Columns></SelectStatement><SQL>

this is @150 line <SQL><SelectStatement modified='1' type='string'><![CDATA[ SEL A.COLUMN_NMAE1, \(D)\(A) A.FIND_REPLCAE FROM TABLE_NAME]]><Tables collapsed='1'></Tables><Parameters collapsed='1'></Parameters><Columns collapsed='1'></Columns></SelectStatement></SQL>

my output:-
<SQL><SelectStatement modified=\\'1\\' type=\\'string\\'><![CDATA[
SEL A.COLUMN_NMAE1,
Trim(A.FIND_REPLCAE)
FROM TABLE_NAME
\><Tables collapsed=\\'1\\'></Tables><Parameters collapsed=\\'1\\'></Parameters><Columns collapsed=\\'1\\'></Columns></SelectStatement><SQL>

<SQL><SelectStatement modified='1' type='string'><![CDATA[ SEL A.COLUMN_NMAE1, \(D)\(A) Trim(A.FIND_REPLCAE) FROM TABLE_NAME]]><Tables collapsed='1'></Tables><Parameters collapsed='1'></Parameters><Columns collapsed='1'></Columns></SelectStatement></SQL>

pan64 10-17-2017 12:48 AM

please use [code]<here comes your script>[/code] tags to keep formatting (please try to edit your original post).
Also please give us more details. Probably you have a perl script already, what did you try (to modify), what's happened....

looks like duplicate of https://www.linuxquestions.org/quest...ce-4175615766/

Turbocapitalist 10-17-2017 01:27 AM

Yes. Please use [code] [/code] tags around your perl script. For example like this,

Code:

#!/usr/bin/perl

use XML::XPath;
use warnings;
use strict;

. . .

exit 0;

You'll most likely use the CPAN module XML::Xpath or something similar.


All times are GMT -5. The time now is 08:13 AM.