is it hard to extract particular lines & strings from the files??

Hi Experts,

I have lots of big size files. Below is the snapshot of a file. From the files i want extract informmation like belows. What could be command or script for that?

DELETE
RESP:940120105

CREATE
RESP:0

GET
RESP:0

File contains like below-
...
...
<log logid="845b16ce190811052359400116">
<category>Upstream</category>
<operation>Delete</operation>
<target>SUB</target>
<instance></instance>
<user>sogadm</user>
<context>sog</context>
<fullOperation>DELETE:SUB:9371068317:PREPAY,1:DEST,ALL;</fullOperation>
<starttime>20081105235940.030937</starttime>
<stoptime>20081106000012.105544</stoptime>
<fullResult>RESP:940120105;;</fullResult>
<status>FAILED</status>
</log>

<log logid="845b16ce190811052359400116">
<category>Upstream</category>
<operation>Create</operation>
<target>SUB</target>
<instance></instance>
<user>sogadm</user>
<context>sog</context>
<fullOperation>CREATE:SUB:9371068317:PREPAY,1:DEST,ALL;</fullOperation>
<starttime>20081105235940.030937</starttime>
<stoptime>20081106000012.105544</stoptime>
<fullResult>RESP:0;</fullResult>
<status>SUCCESSFUL</status>
</log>

<log logid="845b16ce190811060000120118">
<category>Upstream.CAI</category>
<operation>Get</operation>
<target>CSUB</target>
<instance></instance>
<user>sogadm</user>
<context>sog</context>
<fullOperation>GET:CSUB:71068319:POSTPAY,1:DEST,ALL;</fullOperation>
<starttime>20081106000012.310898</starttime>
<stoptime>20081106000045.118912</stoptime>
<fullResult>RESP:0;</fullResult>
<status>SUCCESSFUL</status>
</log>
..
..

Many thanks in advance. //Purple

perl -00nle'
  print join "\n", /<fullOperation>(.*?):.*<fullResult>(.*?);/s
  ' logfile1 [logfile2 .. logfilen]

Hi buddy,

i don't have perl in my sunSolaris 9. Anyother way like using grep/awk or sed ??

hay buddy,

I just copy paste your command in my bash shell. It gave some output. Means i have perl installed :slight_smile:

$ perl -00nle'print join "\n", /<fullOperation>(.*?):.*<fullResult>(.*?);/s' 2008-11-06.0.log

But i think i need to more specified. I need to extract only particular strings from the <fullOperation>. That is-

<fullOperation>CREATE:...*
<fullOperation>DELETE:....*

The reason to do this, in <fullOperation> there are other string which i don't need at all.

what could be the modified script in that case?

This is strange ...
This is the output on my Solaris 9 machine:

$ cat file
<log logid="845b16ce190811052359400116">
<category>Upstream</category>
<operation>Delete</operation>
<target>SUB</target>
<instance></instance>
<user>sogadm</user>
<context>sog</context>
<fullOperation>DELETE:SUB:9371068317:PREPAY,1EST,ALL;</fullOperation>
<starttime>20081105235940.030937</starttime>
<stoptime>20081106000012.105544</stoptime>
<fullResult>RESP:940120105;;</fullResult>
<status>FAILED</status>
</log>


<log logid="845b16ce190811052359400116">
<category>Upstream</category>
<operation>Create</operation>
<target>SUB</target>
<instance></instance>
<user>sogadm</user>
<context>sog</context>
<fullOperation>CREATE:SUB:9371068317:PREPAY,1EST,ALL;</fullOperation>
<starttime>20081105235940.030937</starttime>
<stoptime>20081106000012.105544</stoptime>
<fullResult>RESP:0;</fullResult>
<status>SUCCESSFUL</status>
</log>


<log logid="845b16ce190811060000120118">
<category>Upstream.CAI</category>
<operation>Get</operation>
<target>CSUB</target>
<instance></instance>
<user>sogadm</user>
<context>sog</context>
<fullOperation>GET:CSUB:71068319:POSTPAY,1EST,ALL;</fullOperation>
<starttime>20081106000012.310898</starttime>
<stoptime>20081106000045.118912</stoptime>
<fullResult>RESP:0;</fullResult>
<status>SUCCESSFUL</status>
</log>
..
..
$ perl -00nle'
>   print join "\n", /<fullOperation>(.*?):.*<fullResult>(.*?);/s
>   ' file
DELETE
RESP:940120105

CREATE
RESP:0

GET
RESP:0

Are you sure your <log> tags are separated by empty lines?

Some output? Not necessarily:

$ PATH= perl -00nle'print join "\n",/<fullOperation>(.*?):.*<fullResult>(.*?);/s' file
zsh: command not found: perl

As you see you get some output even if the perl interpreter is not found.

perl -ne '
if(m/<fullOperation>/) {
	@arr=split("[<|>]",$_);
	@temp=split(":",$arr[2]);
	print $temp[0],"\n";
}
if(m/<fullResult>/) {
	@arr=split("[<|>]",$_);
	print $arr[2],"\n";
}' file

Hi experts,

I run thiis command and would like to save the output in a file. If i run it like below it seems its not working..

$ perl -00nle'print join "\n", /<fullOperation>(.*?):.*<fullResult>(.*?);/s' 2008-11-06.0.log > outputlogs.txt

Why? What exactly is happening?