LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 10-17-2017, 12:37 AM   #1
spatil20
LQ Newbie
 
Registered: May 2015
Posts: 21

Rep: Reputation: Disabled
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>
 
Old 10-17-2017, 12:48 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,611

Rep: Reputation: 5606Reputation: 5606Reputation: 5606Reputation: 5606Reputation: 5606Reputation: 5606Reputation: 5606Reputation: 5606Reputation: 5606Reputation: 5606Reputation: 5606
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/

Last edited by pan64; 10-17-2017 at 12:52 AM.
 
Old 10-17-2017, 01:27 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,668
Blog Entries: 3

Rep: Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904
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.
 
  


Closed Thread

Tags
perlscript


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Spreadsheet question find value for column b based on max value in column k davholla General 2 02-28-2014 03:50 AM
how to find match between two rows of column in same file using PERL genetist Linux - Newbie 3 07-13-2013 11:17 AM
[SOLVED] Perl Find and replace line in crontab Sir Todd Programming 2 02-14-2012 02:55 PM
Find and replace a string in a file using perl command from bash script koundinya749 Programming 5 02-15-2011 04:52 PM
How do I Find and Replace text within files using Perl (no one-liners please) GuerillaSquad Programming 3 12-31-2009 09:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration