Sponsored Content
Top Forums Shell Programming and Scripting Extract strings from multiple lines into one csv file Post 302523553 by satish.vampire on Thursday 19th of May 2011 05:26:23 AM
Old 05-19-2011
Hi Ahamed,

I am able to get the location and values correctly right now. Thanks for your help.
But the unncessary data is also coming. Please refer the below output after the execution of the script.
Code
Quote:
#!/usr/bin/awk -f
BEGIN{FS="<|=";print "hostname, gc type, datetime, duration, location, intervalms, percent";"hostname"|getline _1}
/^<af/{split($2,_8," ");_2=_8[1];split($5,_8,"\"");_3=_8[2];split($6,_8,"\"");_6=_8[2]/1000}
/^<tenured/{++i}i==3{i=0;split($5,_8,"\"");_7=_8[2]}
/^<time totalms/{split($3,_8,"\"");_4=_8[2]/1000}
/^<\/af>/{t=split(FILENAME,_8,"/");print _1,_2,_3,_4,_8[t-1],_6,_7} OFS=", "
Output
Quote:
hostname, gc type, datetime, duration, location, intervalms, percent
<af type="tenured" id="1" timestamp="Dec 01 16:43:42 2010" intervalms="0.000">
<minimum requested_bytes="256" />
<time exclusiveaccessms="0.023" />
<tenured freebytes="93952000" totalbytes="1879048192" percent="4" >
<soa freebytes="0" totalbytes="1785096192" percent="0" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<gc type="global" id="1" totalid="1" intervalms="0.000">
<classloadersunloaded count="10" timetakenms="30.975" />
<refs_cleared soft="393" threshold="32" weak="2725" phantom="65238" />
<finalization objectsqueued="46457" />
<timesms mark="128.763" sweep="7.075" compact="0.000" total="167.222" />
<tenured freebytes="1790057144" totalbytes="1879048192" percent="95" >
<soa freebytes="1696105144" totalbytes="1785096192" percent="95" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1790056240" totalbytes="1879048192" percent="95" >
<soa freebytes="1696104240" totalbytes="1785096192" percent="95" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="167.583" />
tkdp2csmftp50, af, Dec 01 16:43:42 2010, 0.167583, PJPbatch, 0,
</af>
<af type="tenured" id="2" timestamp="Dec 02 04:21:04 2010" intervalms="41841721.770">
<minimum requested_bytes="376" />
<time exclusiveaccessms="0.024" />
<tenured freebytes="93952000" totalbytes="1879048192" percent="4" >
<soa freebytes="0" totalbytes="1785096192" percent="0" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<gc type="global" id="2" totalid="2" intervalms="41841722.165">
<classloadersunloaded count="7" timetakenms="30.800" />
<refs_cleared soft="0" threshold="32" weak="42" phantom="81780" />
<finalization objectsqueued="57651" />
<timesms mark="148.836" sweep="7.021" compact="0.000" total="187.096" />
<tenured freebytes="1776411808" totalbytes="1879048192" percent="94" >
<soa freebytes="1682459808" totalbytes="1785096192" percent="94" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1776410904" totalbytes="1879048192" percent="94" >
<soa freebytes="1682458904" totalbytes="1785096192" percent="94" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="187.517" />
tkdp2csmftp50, af, Dec 02 04:21:04 2010, 0.187517, PJPbatch, 41841.7, 4
</af>
How to rip this unnecessary data from the generated values
BTW my OS is Linux

Last edited by satish.vampire; 05-19-2011 at 09:17 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 08:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy