Parsing and filtering multiline text into comma separated line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing and filtering multiline text into comma separated line
# 1  
Old 02-07-2012
Java Parsing and filtering multiline text into comma separated line

I have a log file that contains several reports with following format.
<Start of delimiter> Report1 header
Report1 header continue
Report1 header continue


Record1 header
Record1 header continue
Record1 header continue

field1 field2 field3 field4
------ ------ ------ ------
value1 value2 value3 value4


Record1 header
Record1 header continue
Record1 header continue

field5 field6 field7 field8 field9
------ ------ ------ ------ ------
value5 value6 value7 value8 value9

Record1 header
Record1 header continue
Record1 header continue

field10 field11 field12
------ ------ ------
value10 value11 value12

Report1 Footer
<End of delimiter>
<Start of delimiter> Report2 header
Report2 header continue
Report2 header continue


Record2 header
Record2 header continue
Record2 header continue

field13 field14
------ ------
value13 value14


Record2 header
Record2 header continue
Record2 header continue

field15 field16 field17 field18 field19
------ ------ ------ ------ ------
value15 value16 value17 value18 value19


Report2 Footer
<End of delimiter>

field1, field2 etc are various names and are all different and not necessarily written as field1, field2

I am interested in parsing the log file so that final output looks like this
value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,value11,value12,value13,value 14,value15,value16,value17,value18,value19

I would appreciate if people throw in some ideas on how to filter the log file so that only comma separated values are printed in single line.
# 2  
Old 02-07-2012
You could scan for ------ and then print the next line:
Code:
awk '/-{6}/{getline;$1=$1;print}' OFS=, ORS= infile

to print a linefeed after the output:
Code:
awk '/-{6}/{getline;$1=$1;print} END{print RS}' OFS=, ORS= infile


Last edited by Scrutinizer; 02-07-2012 at 04:12 PM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

AIX put comma separated data on its own line

In Linux you can do this to put comma separated data on its own line like this. sed 's/ */&\n/g' /tmp/ports sed 's/ */\n/g' /tmp/ports How do you do this in AIX? It is not working. Is there another way to do this? Something like this. 1, 2, 3, 4 To look like this. 1 2 3 4 (4 Replies)
Discussion started by: cokedude
4 Replies

2. Shell Programming and Scripting

Parsing Comma Separated values to UNIX variable from PLSQL

Hi All, I'm trying to pass the comma separated values (string) returned from Plsql Procedure to UNIX variable. getting the below log message cat: -: Bad file descriptor awk: cmd. line:1: fatal: error reading input file `-': Bad file descriptor The output coming from plsql procedure is... (3 Replies)
Discussion started by: Mahesh3089
3 Replies

3. Shell Programming and Scripting

awk to change comma separated line to horizontal

I am trying to change a file that looks like this: file, announcement,date, server, server01, server02, server06, file04, rec01, rec04, rec03... etc into a vertical file like this: file announcement date server server01 server02 server06 The file does not have to be sorted... (5 Replies)
Discussion started by: newbie2010
5 Replies

4. Shell Programming and Scripting

Combining multiple block of lines in one comma separated line

Hi Everyone, On my Linux box I have a text file having block of few lines and this block lines separated by one blank line. I would like to format and print these lines in such a way that this entire block of lines will come as single comma separated line & again next block of lines in next... (7 Replies)
Discussion started by: gr8_usk
7 Replies

5. Shell Programming and Scripting

Needs help in parsing comma separated values

hello experts, i am retrieving values in variables jobKey and jobName within my shell script. these values are returned to me within braces and i am using following command to remove those braces: jobKeys=`echo $jobKeys | sed 's:^.\(.*\).$:\1:'` jobNames=`echo $jobNames | sed... (1 Reply)
Discussion started by: avikaljain
1 Replies

6. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

7. Shell Programming and Scripting

Reading Words separated by comma in line

Hi All, I am facing issue, to read words in line, line as follow and i want to read word at each comma 1,you,are,two So i want read like 1 you are two Thanks (1 Reply)
Discussion started by: sujit_kashyap
1 Replies

8. Shell Programming and Scripting

parsing comma separated file

Hi, I have a file with th elist of patches separated by comma, like below: patch1, patch 2, patch 3................ t\The number of patches is not known as it changes every time. I need assistance in writing a routine such as it will take patch1 as first variable and performs the... (4 Replies)
Discussion started by: avikaljain
4 Replies

9. Shell Programming and Scripting

printing sequence of line no. with comma separated

Kindly i want to concatenate every 12 lines ina file, using a comma separator between fields (each line)? can anyone help please? thanks a lot in advance. (5 Replies)
Discussion started by: m_wassal
5 Replies

10. Shell Programming and Scripting

Parsing Comma separated Arguments

Hi unix guru's I want to execute a shell script like ksh printdetails.ksh Andy,Bob,Daisy,Johnson like passing all the four names in the as the arguments and these arguments are varies between 1 to 10. How to pass these names to the shell script variable. and also i want to know the count... (4 Replies)
Discussion started by: Reddy482
4 Replies
Login or Register to Ask a Question