Extract strings from multiple lines into one csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract strings from multiple lines into one csv file
# 1  
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..
# 2  
Old 05-18-2011
Assuming the sample data you have given, try this

Code:
#!/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>/{split(FILENAME,_8,"/");print _1,_2,_3,_4,_8[5],_6,_7} OFS=", "

Put the above code in a script say run and execute it like this

Code:
/user/ahamed/test $ ./run /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch/log
hostname, gc type, datetime, duration, location, intervalms, percent
localhost, af, May 14 13:44:13 2011, 0.680097, EMQbatchprofile, 0.955624, 10
localhost, af, May 14 13:50:13 2011, 8.54001, EMQbatchprofile, 9.23012, 13

If your OS is solaris, please use /usr/xpg4/bin/awk

regards,
Ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 05-19-2011
Thanks for your quick response Ahmed, But I found some difference in between the actual result and expected result. Can you please look into this.
Actual result output
Quote:
hostname, gc type, datetime, duration, location, intervalms, percent
<?xml version="1.0" ?>
<verbosegc version="200811_07">
************ Start Display Current Environment ************
Log file started at: [10/27/10 7:12:50:640 GMT]
************* End Display Current Environment *************
<af type="tenured" id="1" timestamp="Nov 15 22:55:30 2010" intervalms="0.000">
<minimum requested_bytes="80" />
<time exclusiveaccessms="0.025" />
<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="4" timetakenms="74.752" />
<refs_cleared soft="361" threshold="32" weak="1475" phantom="0" />
<finalization objectsqueued="679559" />
<timesms mark="229.402" sweep="5.824" compact="0.000" total="311.549" />
<tenured freebytes="1540577312" totalbytes="1879048192" percent="81" >
<soa freebytes="1446625312" totalbytes="1785096192" percent="81" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1540576416" totalbytes="1879048192" percent="81" >
<soa freebytes="1446624416" totalbytes="1785096192" percent="81" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="314.244" />
tkdp2csmftp50, af, Nov 15 22:55:30 2010, , profiles, 0,
</af>

<?xml version="1.0" ?>
<verbosegc version="200811_07">
************ Start Display Current Environment ************
Log file started at: [11/26/10 4:23:17:674 GMT]
************* End Display Current Environment *************
</verbosegc>
<?xml version="1.0" ?>
<verbosegc version="200811_07">
log4j:WARN [log4j.configDebug] is deprecated. Use [log4j.debug] instead.
************ Start Display Current Environment ************
Log file started at: [12/1/10 7:27:37:925 GMT]
************* End Display Current Environment *************
<af type="tenured" id="2" timestamp="Dec 02 15:17:29 2010" intervalms="64967168.737">
<minimum requested_bytes="200" />
<time exclusiveaccessms="0.032" />
<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="64967168.943">
<classloadersunloaded count="9" timetakenms="41.615" />
<refs_cleared soft="0" threshold="32" weak="3" phantom="0" />
<finalization objectsqueued="26024" />
<timesms mark="36.866" sweep="5.572" compact="0.000" total="84.225" />
<tenured freebytes="1835536744" totalbytes="1879048192" percent="97" >
<soa freebytes="1741584744" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1835535840" totalbytes="1879048192" percent="97" >
<soa freebytes="1741583840" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="84.461" />
tkdp2csmftp50, af, Dec 02 15:17:29 2010, , profiles, 64967.2,
</af>
Expexcted result is
Quote:
hostname, gc type, datetime, duration, location, intervalms, percent
tkdp2csmftp50, af, Nov 15 22:55:30 2010, , profiles, 0,
tkdp2csmftp50, af, Dec 02 15:17:29 2010, , profiles, 64967.2,


hostname, gc type, datetime, intervalms are correct but the duration, location and percent is not populating properly. (Location would be PJPETLbatch where the whole path is /opt/WebSphere61/AppServer/profiles/PJPETLbatchprofile/logs/PJPETLbatch/logfile.log)
And I need the output without any other log information except the above values.
# 4  
Old 05-19-2011
can you paste the sample data you tried?

regards,
Ahamed
# 5  
Old 05-19-2011
Hi Ahamed,

Please find the sample data from the lof file


Quote:
<?xml version="1.0" ?>
<verbosegc version="200811_07">
************ Start Display Current Environment ************
Log file started at: [10/27/10 7:12:50:640 GMT]
************* End Display Current Environment *************
<af type="tenured" id="1" timestamp="Nov 15 22:55:30 2010" intervalms="0.000">
<minimum requested_bytes="80" />
<time exclusiveaccessms="0.025" />
<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="4" timetakenms="74.752" />
<refs_cleared soft="361" threshold="32" weak="1475" phantom="0" />
<finalization objectsqueued="679559" />
<timesms mark="229.402" sweep="5.824" compact="0.000" total="311.549" />
<tenured freebytes="1540577312" totalbytes="1879048192" percent="81" >
<soa freebytes="1446625312" totalbytes="1785096192" percent="81" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1540576416" totalbytes="1879048192" percent="81" >
<soa freebytes="1446624416" totalbytes="1785096192" percent="81" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="314.244" />
</af>

<?xml version="1.0" ?>
<verbosegc version="200811_07">
************ Start Display Current Environment ************
Log file started at: [11/26/10 4:23:17:674 GMT]
************* End Display Current Environment *************
</verbosegc>
<?xml version="1.0" ?>
<verbosegc version="200811_07">
log4j:WARN [log4j.configDebug] is deprecated. Use [log4j.debug] instead.
************ Start Display Current Environment ************
Log file started at: [12/1/10 7:27:37:925 GMT]
************* End Display Current Environment *************
<af type="tenured" id="1" timestamp="Dec 01 21:14:42 2010" intervalms="0.000">
<minimum requested_bytes="48" />
<time exclusiveaccessms="0.022" />
<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="12" timetakenms="47.053" />
<refs_cleared soft="393" threshold="32" weak="2487" phantom="0" />
<finalization objectsqueued="20322" />
<timesms mark="44.634" sweep="6.555" compact="0.000" total="98.408" />
<tenured freebytes="1837688976" totalbytes="1879048192" percent="97" >
<soa freebytes="1743736976" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1837688072" totalbytes="1879048192" percent="97" >
<soa freebytes="1743736072" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="98.611" />
</af>
<af type="tenured" id="2" timestamp="Dec 02 15:17:29 2010" intervalms="64967168.737">
<minimum requested_bytes="200" />
<time exclusiveaccessms="0.032" />
<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="64967168.943">
<classloadersunloaded count="9" timetakenms="41.615" />
<refs_cleared soft="0" threshold="32" weak="3" phantom="0" />
<finalization objectsqueued="26024" />
<timesms mark="36.866" sweep="5.572" compact="0.000" total="84.225" />
<tenured freebytes="1835536744" totalbytes="1879048192" percent="97" >
<soa freebytes="1741584744" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1835535840" totalbytes="1879048192" percent="97" >
<soa freebytes="1741583840" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="84.461" />
</af>
<af type="tenured" id="3" timestamp="Dec 03 09:18:55 2010" intervalms="64885769.755">
<minimum requested_bytes="200" />
<time exclusiveaccessms="0.022" />
<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="3" totalid="3" intervalms="64885769.920">
<classloadersunloaded count="10" timetakenms="45.009" />
<refs_cleared soft="0" threshold="32" weak="6" phantom="0" />
<finalization objectsqueued="25992" />
<timesms mark="37.044" sweep="5.616" compact="0.000" total="87.835" />
<tenured freebytes="1835551552" totalbytes="1879048192" percent="97" >
<soa freebytes="1741599552" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1835550648" totalbytes="1879048192" percent="97" >
<soa freebytes="1741598648" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="88.022" />
</af>
<af type="tenured" id="4" timestamp="Dec 04 03:20:35 2010" intervalms="64900049.085">
<minimum requested_bytes="80" />
<time exclusiveaccessms="0.022" />
<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="4" totalid="4" intervalms="64900049.279">
<classloadersunloaded count="8" timetakenms="38.021" />
<refs_cleared soft="0" threshold="32" weak="3" phantom="0" />
<finalization objectsqueued="25998" />
<timesms mark="36.790" sweep="5.527" compact="0.000" total="80.503" />
<tenured freebytes="1835518208" totalbytes="1879048192" percent="97" >
<soa freebytes="1741566208" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
</gc>
<tenured freebytes="1835517304" totalbytes="1879048192" percent="97" >
<soa freebytes="1741565304" totalbytes="1785096192" percent="97" />
<loa freebytes="93952000" totalbytes="93952000" percent="100" />
</tenured>
<time totalms="80.720" />
</af>
<af type="tenured" id="5" timestamp="Dec 04 21:22:04 2010" intervalms="64888700.530">
<minimum requested_bytes="80" />
<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="5" totalid="5" intervalms="64888700.703">
<classloadersunloaded count="10" timetakenms="39.908" />
<refs_cleared soft="0" threshold="32" weak="6" phantom="0" />
<finalization objectsqueued="25990" />
<timesms mark="36.152" sweep="5.605" compact="0.000" total="81.829" />
<tenured freebytes="1835509608" totalbytes="1879048192" percent="97" >
<soa freebytes="1760348008" totalbytes="1803886592" percent="97" />
<loa freebytes="75161600" totalbytes="75161600" percent="100" />
</tenured>
</gc>
<tenured freebytes="1835508704" totalbytes="1879048192" percent="97" >
<soa freebytes="1760347104" totalbytes="1803886592" percent="97" />
<loa freebytes="75161600" totalbytes="75161600" percent="100" />
</tenured>
<time totalms="82.025" />
</af>
<af type="tenured" id="6" timestamp="Dec 05 15:35:11 2010" intervalms="65586596.415">
<minimum requested_bytes="80" />
<time exclusiveaccessms="0.024" />
<tenured freebytes="75161600" totalbytes="1879048192" percent="3" >
<soa freebytes="0" totalbytes="1803886592" percent="0" />
<loa freebytes="75161600" totalbytes="75161600" percent="100" />
</tenured>
<gc type="global" id="6" totalid="6" intervalms="65586596.587">
<classloadersunloaded count="10" timetakenms="36.938" />
<refs_cleared soft="0" threshold="32" weak="3" phantom="0" />
<finalization objectsqueued="26273" />
<timesms mark="36.522" sweep="5.575" compact="0.000" total="79.200" />
<tenured freebytes="1835368576" totalbytes="1879048192" percent="97" >
<soa freebytes="1778997376" totalbytes="1822676992" percent="97" />
<loa freebytes="56371200" totalbytes="56371200" percent="100" />
</tenured>
</gc>
<tenured freebytes="1835367672" totalbytes="1879048192" percent="97" >
<soa freebytes="1778996472" totalbytes="1822676992" percent="97" />
<loa freebytes="56371200" totalbytes="56371200" percent="100" />
</tenured>
<time totalms="79.396" />
</af>
---------- Post updated at 12:27 PM ---------- Previous update was at 12:17 PM ----------

Expected result from the above sample data

Quote:
hostname, gc type, datetime, duration, location, intervalms, percent
tkdp2csmftp50, af, Nov 15 22:55:30 2010, .314244, PJPETLbatch, 0, 81
tkdp2csmftp50, af, Dec 01 21:14:42 2010, .098611, PJPETLbatch, 0, 97
tkdp2csmftp50, af, Dec 02 15:17:29 2010, .084461, PJPETLbatch, 64967.2, 97
tkdp2csmftp50, af, Dec 03 09:18:55 2010, .088022, PJPETLbatch, 64885.8, 97
tkdp2csmftp50, af, Dec 04 03:20:35 2010, .080720, PJPETLbatch, 64900, 97
tkdp2csmftp50, af, Dec 04 21:22:04 2010, .082025, PJPETLbatch, 64888.7, 97
tkdp2csmftp50, af, Dec 05 15:35:11 2010, .079396, PJPETLbatch, 65586.6, 97
# 6  
Old 05-19-2011
I am getting the correct output. For the location, a minor change may be required.

Code:
#!/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=", "

Code:
/user/ahamed/test $ ./run f
hostname, gc type, datetime, duration, location, intervalms, percent
localhost, af, Nov 15 22:55:30 2010, 0.314244, f, 0, 81
localhost, af, Dec 02 15:17:29 2010, 0.084461, f, 64967.2, 97
...

Here the location is different cause I didnt give the full path.

regards,
Ahamed

Last edited by ahamed101; 05-19-2011 at 04:20 AM..
This User Gave Thanks to ahamed101 For This Post:
# 7  
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..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

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