How to add line breaks to perl command with large text in single quotes?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add line breaks to perl command with large text in single quotes?
# 1  
Old 06-13-2016
How to add line breaks to perl command with large text in single quotes?

Below code extracts multiple field values from XML into array and prints all in one line.
Code:
perl -nle '@r=/(?: jndiName| authDataAlias| value| minConnections| maxConnections| connectionTimeout| name)="([^"]+)/g and print join ",",$ENV{tIPnSCOPE},$ENV{pr
ovider},$ENV{impClassName},@r[0,1,2,4,5,6,7]' server.xml

There are other statements that are larger than this..
How can I add line breaks to large text in single quotes?
If I can't do that.. how can I pass static text as variable[s] in single quotes?
# 2  
Old 06-13-2016
Could you please be more specific? Show the input you have, the output you have, and the output you want.
# 3  
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
# 4  
Old 06-14-2016
Quote:
Originally Posted by kchinnam
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?

[...]
[/CODE]
$ENV{var} is the facility that Perl has to interact with shell environment variables. Another way is to pass them as command line parameters, but in order to do that you have to write more infrastructure code to receive them, and I am afraid you are pushing a little too far the design of the one-liner I gave you.
Perhaps, it is time to consider creating a more usable script, instead of a command line one.

In any case, you can break the one-line at after each and, like so:

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

This User Gave Thanks to Aia For This Post:
# 5  
Old 06-15-2016
Awsome, Aia
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question