Sponsored Content
Top Forums Shell Programming and Scripting Extract strings from multiple lines into one csv file Post 302523267 by satish.vampire on Wednesday 18th of May 2011 09:23:05 AM
Old 05-18-2011
Extract strings from multiple lines into one csv file

Hi all,

Please go through my requirement.
I have a log file in the location /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch
This file contains the follwing pattern data
Code:
<af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624">
<minimum requested_bytes="200" />
<time exclusiveaccessms="0.055" />
<tenured freebytes="0" totalbytes="2147483648" percent="0" >
<soa freebytes="0" totalbytes="2147483648" percent="0" />
<loa freebytes="0" totalbytes="0" percent="0" />
</tenured>
<gc type="global" id="42" totalid="42" intervalms="956.093">
<refs_cleared soft="2665" threshold="32" weak="341" phantom="6" />
<finalization objectsqueued="109" />
<timesms mark="661.941" sweep="17.140" compact="0.000" total="679.629" />
<tenured freebytes="227799624" totalbytes="2147483648" percent="10" >
<soa freebytes="227799624" totalbytes="2147483648" percent="10" />
<loa freebytes="0" totalbytes="0" percent="0" />
</tenured>
</gc>
<tenured freebytes="227799080" totalbytes="2147483648" percent="10" >
<soa freebytes="227799080" totalbytes="2147483648" percent="10" />
<loa freebytes="0" totalbytes="0" percent="0" />
</tenured>
<time totalms="680.097" />
</af>
<af type="tenured" id="43" timestamp="May 14 13:50:13 2011" intervalms="9230.118">
<minimum requested_bytes="200" />
<time exclusiveaccessms="0.055" />
<tenured freebytes="0" totalbytes="2147483648" percent="0" >
<soa freebytes="0" totalbytes="2147483648" percent="0" />
<loa freebytes="0" totalbytes="0" percent="0" />
</tenured>
<gc type="global" id="42" totalid="42" intervalms="956.093">
<refs_cleared soft="2665" threshold="32" weak="341" phantom="6" />
<finalization objectsqueued="109" />
<timesms mark="661.941" sweep="17.140" compact="0.000" total="679.629" />
<tenured freebytes="227799624" totalbytes="2147483648" percent="10" >
<soa freebytes="227799624" totalbytes="2147483648" percent="10" />
<loa freebytes="0" totalbytes="0" percent="0" />
</tenured>
</gc>
<tenured freebytes="227799080" totalbytes="2147483648" percent="13" >
<soa freebytes="227799080" totalbytes="2147483648" percent="10" />
<loa freebytes="0" totalbytes="0" percent="0" />
</tenured>
<time totalms="8540.01" />
</af>

Based on the above data I need to generate a csv file which is shown below.
Desired Output:
Code:
hostname, gc type, datetime, duration, location, intervalms, percent
tkdp2csmftp50, af, May 14 13:44:13 2011, 0.680097, EMQbatchprofile, .955624, 10
tkdp2csmftp50, af, May 14 13:50:13 2011, 8.54001, EMQbatchprofile, 9.230118, 13

In the desired output tkdp2csmftp50 is the hostname and the timings (Fields duration and intervalms)which are in millisecs needs to be converted in secs (divided by thousand) and location should be the from the directory path given above (/opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch)

Last edited by pludi; 05-18-2011 at 10:48 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract strings from file and display in csv format

Hello All, I have a file whose data looks something like this I want to extract just the id, name and city fields in a csv format and sort them by id. Output should look like this. 1,psi,zzz 2,beta,pqr 3,theta,xyz 4,alpha,abc 5,gamma,jkl (12 Replies)
Discussion started by: grajp002
12 Replies

2. UNIX for Dummies Questions & Answers

Help please, extract multiple lines from a text file

Hi all, I need to extract lines between the lines 'RD' and 'QA' from a text file (following). there are more that one of such pattern in the file and I need to extract all of them. however, the number of lines between them is varied in the file. Therefore, I can not just use 'grep -A' command.... (6 Replies)
Discussion started by: johnshembb
6 Replies

3. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

4. Shell Programming and Scripting

Extract strings from multiple lines into one file -

input file Desired csv output gc_type, date/time, milli secs af, Mar 17 13:09:04 2011, 144.596 af, Mar 20 00:37:37 2011, 144.242 af, ar 20 21:30:59 2011, 108.518 Hi All, Any help in acheiving the above would be appreciated. I would like to parse through lines within one file and... (5 Replies)
Discussion started by: satish.vampire
5 Replies

5. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

6. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

7. Shell Programming and Scripting

awk? extract quoted "" strings from multiple lines.

I am trying to extract multiple strings from snmp-mib files like below. ----- $ cat IF-MIB.mib <snip> linkDown NOTIFICATION-TYPE OBJECTS { ifIndex, ifAdminStatus, ifOperStatus } STATUS current DESCRIPTION "A linkDown trap signifies that the SNMP entity, acting in... (5 Replies)
Discussion started by: genzo
5 Replies

8. Shell Programming and Scripting

Extract a pattern from multiple lines in a file

I have a file that has some lines starts with * I want to get these lines, then get the word between "diac" and "lex". ex. file: ;;WORD AlAx *0.942490 diac:Al>ax lex:>ax_1 bw:Al/DET+>ax/NOUN+ gloss:brother pos:noun prc3:0 prc2:0 prc1:0 prc0:Al_det per:na asp:na vox:na mod:na gen:m num:s... (4 Replies)
Discussion started by: Viernes
4 Replies

9. Shell Programming and Scripting

Exclude lines in a file with matches with multiple Strings using egrep

Hi I have a txt file and I would like to use egrep without using -v option to exclude the lines which matches with multiple Strings. Let's say I have some text in the txt file. The command should not fetch lines if they have strings something like CAT MAT DAT The command should fetch me... (4 Replies)
Discussion started by: Sathwik
4 Replies

10. Solaris

How to find multiple strings on different lines in file?

Hello, I have spent considerable amount of time breaking my head on this and reached out here. here is the back ground. OS - Solaris 10 There are two strings '<Orin>sop' and '<Dup>two' which I wanted to look for in a file without the quotes on different lines and ONLY if both strings are... (5 Replies)
Discussion started by: keithTait309875
5 Replies
All times are GMT -4. The time now is 05:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy