Sponsored Content
Top Forums Shell Programming and Scripting How to add line breaks to perl command with large text in single quotes? Post 302975499 by kchinnam on Tuesday 14th of June 2016 09:43:35 AM
Old 06-14-2016
Here is simplified case..
perl one liner can get quite big if we have to extract more fields from XML.
So how can we break text in single quotes perl -nle '</regex/ and all kinds of logic' resources.xml into multiple lines for readability?
is there a different way to pass parameters, other than export var; then perl -nle '<$ENV{var}>' approach?

input --> resources.xml
Code:
    <factories xmi:type="resources.jms.mqseries:MQQueue" xmi:id="MQQueue_11111" name="Queue1" jndiName="jms/Queue1" description="Queue1" category="TEST" persistence="APPLICATION_DEFINED" priority="APPLICATION_DEFINED" specifiedPriority="0" expiry="APPLICATION_DEFINED" specifie dExpiry="0" baseQueueName="TEST.QUEUE1" baseQueueManagerName="" useNativeEncoding="false" integerEncoding="Normal" decimalEncoding="Normal" floatingPointEncoding="IEEENormal" targetClient="JMS" queueManagerHost="" queueManagerPort="0" serverConnectionChannelName="" userName="" password="{xor}" readAhead="NO"/>
	
    <factories xmi:type="resources.jms.mqseries:MQQueue" xmi:id="MQQueue_22222" name="Queue2" jndiName="jms/Queue2" description ="Queue2" category="TEST" persistence="APPLICATION_DEFINED" priority="APPLICATION_DEFINED" specifiedPriority="0" expiry="APPLICATION_DEFINED" specifiedExpiry="0" baseQueueName="TEST.QUEUE2" baseQueueManagerName="" useNativeEncoding="false" integerEncoding="Normal" decimalEncoding="Normal" floa tingPointEncoding="IEEENormal" targetClient="JMS" queueManagerHost="" queueManagerPort="0" serverConnectionChannelName="" userName="" password="{xor}" readAhead="NO"/>

Command
Code:
	perl -nle '/<factories.*baseQueueName/ and @r=/(?:jndiN|baseQueueN|n)ame="([^"]+)/g and print join ",",@r[1,2,0]' resources.xml

Output
Code:
jms/Queue1,TEST.QUEUE1,Queue1
jms/Queue2,TEST.QUEUE2,Queue2


Last edited by kchinnam; 06-14-2016 at 10:46 AM.. Reason: formatting
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to add a single line to middle of text file.

I've got a configuration file that is filled with xml text statements for example: <...../> <...../> <...../> <data id="java-options" value="-server -Djava.security.policy..../> <...../> <...../> <...../> I want to write a korn shell script that will go to this specific line and add a... (2 Replies)
Discussion started by: progkcp
2 Replies

2. UNIX for Dummies Questions & Answers

Add single quotes in string

Hi All, I love this site, it helps newbie people like me and I appreciate everyone's help! Here is my questions. I am trying to concatenate a single quote into a character/string from a text file for each line (lets say ABC should look like 'ABC'). I tried to use awk print command to do... (1 Reply)
Discussion started by: mrjunsy
1 Replies

3. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

4. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

5. Shell Programming and Scripting

Search replace strings between single quotes in a text file

Hi There... I need to serach and replace a strings in a text file. My file has; books.amazon='Let me read' and the output needed is books.amazon=NONFOUND pls if anybody know this can be done in script sed or awk.. i have a list of different strings to be repced by NONFOUND.... (7 Replies)
Discussion started by: Hiano
7 Replies

6. Shell Programming and Scripting

How to fix line breaks format text for huge files?

Hi, I need to correct line breaks for huge files (more than 1MM records in a file) and then format it properly. Except the header and trailer, each record starts with 'D'. Requirement:Scan the whole file except the header and trailer records and see if any of the records start with... (19 Replies)
Discussion started by: kikionline
19 Replies

7. Shell Programming and Scripting

[Solved] Need to add Single quotes to particular lines

Hi Guys, I have the following file. DbName=DBNAME DbUser=USERID DbPass=PASSLL SrcLocation=/appl/data/VSTAR SrcFile1=gmb_dly_ind_sls_20120410133424.txt SrcFile2= IpLocation=/appl/data/VSTAR/global_daily/input/GMB IpFile=gmb_dly_ind_sls_20120410133424.txt... (4 Replies)
Discussion started by: mac4rfree
4 Replies

8. Shell Programming and Scripting

How to mege with quotes in single line?

Hi I have input vi file as below a000000 b000000 c000000 d000000 Need output as below 'a000000','b000000','c000000','d000000' Please let us know how to do it (3 Replies)
Discussion started by: buzzme
3 Replies

9. Shell Programming and Scripting

Convert text to lower case except the strings within single quotes

Shell : bash that comes with RHEL 6.7 I have SQL scripts like below. I want to convert all the text in these files to lower case except the strings enclosed within single quotes . Any idea how I can achieve this ? Sample text: $ cat sample.txt SELECT ... (6 Replies)
Discussion started by: John K
6 Replies

10. Shell Programming and Scripting

Remove single-line breaks only in document

Regarding copy/pasted text of copyright-free book from archive.org (link below), in attempt to expand single-line-break paragraph text (not section headings or paragraph breaks) to wider right margin, Justify or Wrap in LIbreOffice is not working, and Find/Replace the paragraph mark ($) wraps all... (2 Replies)
Discussion started by: p1ne
2 Replies
MKDoc::XML::Dumper(3pm) 				User Contributed Perl Documentation				   MKDoc::XML::Dumper(3pm)

NAME
MKDoc::XML::Dumper - Same as Data::Dumper, but with XML SYNOPSIS
use MKDoc::XML::Dumper; use Test::More 'no_plan'; my $stuff = [ qw /foo bar baz/, [], { hello => 'world', yo => \'boo' } ]; my $xml = MKDoc::XML::Dumper->perl2xml ($stuff); my $stuff2 = MKDoc::XML::Dumper->xml2perl ($xml); is_deeply ($stuff, $stuff2); # prints 'ok' SUMMARY
MKDoc::XML::Dumper provides functionality equivalent to Data::Dumper except that rather than serializing structures into a Perl string, it serializes them into a generic XML file format. Of course since XML cannot be evaled, it also provides a mechanism for undumping the xml back into a perl structure. MKDoc::XML::Dumper supports scalar references, hash references, array references, reference references, and litterals. It also supports circular structures and back references to avoid creating unwanted extra copies of the same object. That's all there is to it! API
my $xml = MKDoc::XML::Dumper->perl2xml ($perl); Turns $perl into an XML string. For instance: my $perl = [ qw /foo bar baz/, { adam => 'apple', bruno => 'berry', chris => 'cherry' } ]; print MKDoc::XML::Dumper->perl2xml ($perl);' Will print something like: <array id="135338912"> <item key="0"> <litteral>foo</litteral> </item> <item key="1"> <litteral>bar</litteral> </item> <item key="2"> <litteral>baz</litteral> </item> <item key="3"> <hash id="135338708"> <item key="bruno"> <litteral>berry</litteral> </item> <item key="adam"> <litteral>apple</litteral> </item> <item key="chris"> <litteral>cherry</litteral> </item> </hash> </item> </array> As you can see, every object has an id. This allows for backreferencing, so: my $perl = undef; $perl = $perl; print MKDoc::XML::Dumper->perl2xml ($perl);' Prints something like: <ref id="135338888"> <backref id="135338888" /> </ref> For the curious, these identifiers are computed using some perl black magic: my $id = 0 + $reference; my $perl = MKDoc::XML::Dumper->perl2xml ($xml); Does the exact reverse operation as xml2perl(). AUTHOR
Copyright 2003 - MKDoc Holdings Ltd. Author: Jean-Michel Hiver This module is free software and is distributed under the same license as Perl itself. Use it at your own risk. SEE ALSO
MKDoc::XML::Decode MKDoc::XML::Encode perl v5.10.1 2004-10-06 MKDoc::XML::Dumper(3pm)
All times are GMT -4. The time now is 09:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy