Split line in to 3 lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split line in to 3 lines
# 8  
Old 11-17-2010
@raghunsi

Quote:
Originally Posted by Scrutinizer
Code:
sed 's|<\([A-Z]*\)>.*</\1>|\n&\n|g' infile

Code:
sed 's|<\(RE[A-Z]*\)>.*</\1>|\n&\n|g' infile

Code:
sed 's|<\(REQUEST\)>.*</\1>|\n&|;s|<\(RESPONSE\)>.*</\1>|\n&|' infile

If you are on Solaris, better use /usr/xpg4/bin/sed .
Add another \n and try again as above..
# 9  
Old 11-17-2010
why not these ones
Code:
sed 's/<REQUEST>\(.*\)<RESPONSE>\(.*\)/\n<REQUEST>\1\n<RESPONSE>\2/'

# 10  
Old 11-18-2010
Scrutinizer,

By using your syntax i could see only first line of the file is being formatted . But not rest of all.
So here is output of the syntax

Code:
2010-11-16 00:45:12,314

n<REQUEST><VALIDATION-ERROR><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><wsMessageHeader xmlns="http://integration.xyz.co
m/common/header/WSMessageHeader/v2"><trackingMessageHeader><applicationId>HJS</applicationId><applicationUserId>HJS</applicationUserId><consumerId>1001</consumerId><message
Id>1289889915199</messageId><conversationId>1001</conversationId><timeToLive>123</timeToLive><messageDateTimeStamp>2010-11-16T00:45:15.199-06:00</messageDateTimeStamp></tra
ckingMessageHeader><securityMessageHeader/></wsMessageHeader></soapenv:Header><soapenv:Body><managetypelist xmlns="http://integration.xyz.com/interfaces/manageControl
List/v1/managetypelist.xsd"><userIdentityInfo><ownerId>4350190</ownerId><ownerType>MDN</ownerType></userIdentityInfo><typelist><listName>BlockList</listName><conte
xtName>BlockList</contextName></typelist><authentication><loginId>1672</loginId><realm>SITEMINDER</realm><roleList><roleInfo><role>AccountHolder</role></roleInfo></r
oleList></authentication></managetypelist></soapenv:Body></soapenv:Envelope></VALIDATION-ERROR></REQUEST>n

n<RESPONSE><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>Client.705</faultcode><faultstring>Input
validation error</faultstring><faultactor>76S</faultactor><detail><ns1:errorDetailItem xmlns:ns1="http://integration.xyz.com/common/ErrorDetails.xsd"><ns1:providerError>
<ns1:providerErrorCode>Client.705</ns1:providerErrorCode><ns1:providerErrorText>ManagementService: cvc-particle 3.1: in elemen
t typelist of type typelistType, found &lt;/typelist>, but next item should be any of [deletetypelistInd, typelistInfo]</ns1:providerErrorText></ns1:provider
Error></ns1:errorDetailItem></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope></RESPONSE>n

But rest of all other lines remains the same , given below is the same

Code:
2010-11-16 00:45:12,314n<REQUEST><VALIDATION-ERROR><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><wsMessageHeader xmlns="http://integration.xyz.com/common/header/WSMessageHeader/v2"><trackingMessageHeader><applicationId>HJS</applicationId><applicationUserId>HJS</applicationUserId><consumerId>1001</consumerId><messageId>1289889915199</messageId><conversationId>1001</conversationId><timeToLive>123</timeToLive><messageDateTimeStamp>2010-11-16T00:45:15.199-06:00</messageDateTimeStamp></trackingMessageHeader><securityMessageHeader/></wsMessageHeader></soapenv:Header><soapenv:Body>
<managetypelist xmlns="http://integration.xyz.com/interfaces/manageControlList/v1/managetypelist.xsd"><userIdentityInfo><ownerId>4350190</ownerId>
<ownerType>MDN</ownerType></userIdentityInfo><typelist><listName>BlockList</listName><contextName>BlockList</contextName>
</typelist><authentication><loginId>1672</loginId><realm>SITEMINDER</realm><roleList><roleInfo><role>AccountHolder</role></roleInfo></r
oleList></authentication></managetypelist></soapenv:Body></soapenv:Envelope></VALIDATION-ERROR></REQUEST>nn<RESPONSE><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>Client.705</faultcode><faultstring>Input
validation error</faultstring><faultactor>76S</faultactor><detail><ns1:errorDetailItem xmlns:ns1="http://integration.xyz.com/common/ErrorDetails.xsd"><ns1:providerError>
<ns1:providerErrorCode>Client.705</ns1:providerErrorCode><ns1:providerErrorText>ManagementService: cvc-particle 3.1: in elemen
t typelist of type typelistType, found &lt;/typelist>, but next item should be any of [deletetypelistInd, typelistInfo]</ns1:providerErrorText></ns1:provider
Error></ns1:errorDetailItem></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope></RESPONSE>n

# 11  
Old 11-18-2010
raghunsi, can it be that you are leaving out the single quotes? They should be there.... (sed 's... )
# 12  
Old 11-18-2010
Scrutinizer,

I used the example with ingle quote, but the the output remains the same. I even used with below syntx

Code:
sed -e 's|<\(RE[A-Z]*\)>.*</\1>|\n&\n|g' altered.log > log1.log

The result remains the same. It edits only the first line of the file.
# 13  
Old 11-19-2010
Hi Raghunsi,
Not an expert in sed and awk, but i have tried this using shell
Code:
#/usr/bin/ksh

while read var
do
 echo "${var%%\<*}\n"
 var1=`echo "<"${var#*\<}`
 echo "${var1%%\<RESPONSE*}\n"
 echo ${var#*\</REQUEST} | cut -c2-
 echo "\n"
done <input

# 14  
Old 11-19-2010
So you used:
Code:
/usr/xpg4/bin/sed -e 's|<\(RE[A-Z]*\)>.*</\1>|\n&\n|g' altered.log > log1.log

And that altered only the first line?
Can you post part of your actual input file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Search for a pattern in a file and split the line into two lines

Hi All, Greetings everyone !!! I have a file which has many lines, out of which one line is as below. I need to search for pattern "varchar(30) Select" and if exists, then split the line as below. I am trying to achieve this in ksh. Can anyone help me on this. (8 Replies)
Discussion started by: Pradhikshan
8 Replies

3. Shell Programming and Scripting

Split a line into multiple lines based on delimeters

Hi, I need help to split any lines that contain ; or , input.txtAc020 Not a good chemical process AC030 many has failed, 3 still maintained AC040 Putative; epithelial cells AC050 Predicted binding activity AC060 rodC Putative; upregulated in 48;h biofilm vs planktonic The output... (8 Replies)
Discussion started by: redse171
8 Replies

4. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

5. Shell Programming and Scripting

How do I split a single-line input into five lines?

Example input: John:Shepherd:770-767-4040:U.S.A:New York Mo Jo:Jo Jo: 666-666-6666:U.S.A:Townsville Expected Output: First Name: John Last Name: Shepherd Phone Number: 770-767-4040 Country: U.S.A State: New York First Name: Mo Jo Last Name: Jo Jo Phone Number: 666-666-6666... (10 Replies)
Discussion started by: Camrikron
10 Replies

6. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

7. Shell Programming and Scripting

split single line into two line or three lines

Dear All, I want to split single line into two line or three lines wherever “|” separated values comes using Input line test,DEMTEMPUT20100404010012,,,,,,,,|0070086|0070087, output shoule be test,DEMTEMPUT20100404010012,,,,,,,,0070086, test,DEMTEMPUT20100404010012,,,,,,,,0070087, (14 Replies)
Discussion started by: arvindng
14 Replies

8. Shell Programming and Scripting

Split a line on positions before reading complete line

Hi, I want to split before reading the complete line as the line is very big and its throwing out of memory. can you suggest. when i say #cat $inputFile | while read eachLine and use the eachLine to split its throwing out of memory as the line size is more than 10000000 characters. Can you... (1 Reply)
Discussion started by: vijaykrc
1 Replies

9. UNIX for Dummies Questions & Answers

Split data into multiple lines

All, I have a requirement where I will need to split a line into multiple lines. Ex: Input: 2ABCDEFGH2POIYUY2ASDGGF2QWERTY Output: 2ABCDEFGH 2POIYUY 2ASDGGF 2QWERTY The data is of no fixed lenght. Only the lines have to start with 2. How can this be done. (5 Replies)
Discussion started by: kingofprussia
5 Replies

10. Shell Programming and Scripting

Split a huge line into multiple 120 characters lines with sed?

Hello , I'm trying to split a file which contains a single very long line. My aim is to split this single line each 120 characters. I tried with the sed command : `cat ${MYPATH}/${FILE}|sed -e :a -e 's/^.\{1,120\}$/&\n/;ta' >{MYPATH}/${DEST}` but when I wc -l the destination file it is... (2 Replies)
Discussion started by: jerome_1664
2 Replies
Login or Register to Ask a Question