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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting is it hard to extract particular lines & strings from the files??
# 1  
Old 11-13-2008
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,1SmilieEST,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,1SmilieEST,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,1SmilieEST,ALL;</fullOperation>
<starttime>20081106000012.310898</starttime>
<stoptime>20081106000045.118912</stoptime>
<fullResult>RESP:0;</fullResult>
<status>SUCCESSFUL</status>
</log>
..
..

Many thanks in advance. //Purple
# 2  
Old 11-13-2008
Code:
perl -00nle'
  print join "\n", /<fullOperation>(.*?):.*<fullResult>(.*?);/s
  ' logfile1 [logfile2 .. logfilen]

# 3  
Old 11-13-2008
Hi buddy,

i don't have perl in my sunSolaris 9. Anyother way like using grep/awk or sed ??
# 4  
Old 11-13-2008
hay buddy,

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


$ 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?
# 5  
Old 11-13-2008
This is strange ...
This is the output on my Solaris 9 machine:

Code:
$ 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?
# 6  
Old 11-13-2008
Quote:
Originally Posted by thepurple
I just copy paste your command in my bash shell. It gave some output. Means i have perl installed Smilie
[...]
Some output? Not necessarily:

Code:
$ 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.
# 7  
Old 11-14-2008
Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Match patterns between two files and extract certain range of strings

Hi, I need help to match patterns from between two different files and extract region of strings. inputfile1.fa >l-WR24-1:1 GCCGGCGTCGCGGTTGCTCGCGCTCTGGGCGCTGGCGGCTGTGGCTCTACCCGGCTCCGG GGCGGAGGGCGACGGCGGGTGGTGAGCGGCCCGGGAGGGGCCGGGCGGTGGGGTCACGTG... (4 Replies)
Discussion started by: bunny_merah19
4 Replies

2. UNIX for Beginners Questions & Answers

How to extract the partial matching strings among two files?

I have a two file as shown below, file:1 >Contig_152_415 (REVERSE SENSE) >Contig_152_420 (REVERSE SENSE) >Contig_152_472 (REVERSE SENSE) >Contig_152_484 (REVERSE SENSE) File:2 >Contig_152:49081-49929 ATCGAGCAGCGCCGCGTGCGGTGCACCCTTGTGCAGATCGGGAGTAACCACGCGCACGGC... (2 Replies)
Discussion started by: dineshkumarsrk
2 Replies

3. Shell Programming and Scripting

Concatenating 2 lines from 2 files having matching strings

Hello All Unix Users, I am still new to Unix, however I am eager to learn it.. I have 2 files, some lines have some matching substrings, I would like to concatenate these lines into one lines, leaving other untouched. Here below is an example for that.. File 1 (fasta file): >292183... (6 Replies)
Discussion started by: Mohamed EL Hadi
6 Replies

4. Shell Programming and Scripting

Finding a text in files & replacing it with unique strings

Hallo Everyone. I have to admit I'm shell scripting illiterate . I need to find certain strings in several text files and replace each of the string by unique & corresponding text. I prepared a csv file with 3 columns: <filename>;<old_pattern>;<new_pattern> ... (5 Replies)
Discussion started by: gordom
5 Replies

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

6. Shell Programming and Scripting

Compare one files with strings from another + remove lines

Have two files and want to compare the content of file1 with file2. When matched remove the line. awk 'NR==FNR {b; next} !(b in $0)' file1 file2file1 1. if match 2. removefile2 1. this line has to be removed if match 2. this line has a match, remove 3. this line has no match, no removingThe... (3 Replies)
Discussion started by: sdf
3 Replies

7. Shell Programming and Scripting

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 <af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624"> <minimum... (8 Replies)
Discussion started by: satish.vampire
8 Replies

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

9. Shell Programming and Scripting

Extract lines between 2 strings add white space

I'm trying to extract all the lines between 2 strings (including the lines containing the strings) To make the strings unique I need to include white space if possible. I'm not certain how to do that. sed -n '/ string1 /,/string2/p' infile > outfile & (4 Replies)
Discussion started by: dcfargo
4 Replies

10. Shell Programming and Scripting

AWK: How to extract text lines between two strings

Hi. I have a text test1.txt file like:Receipt Line1 Line2 Line3 End Receipt Line4 Line5 Line6 Canceled Receipt Line7 Line8 Line9 End (9 Replies)
Discussion started by: TQ3
9 Replies
Login or Register to Ask a Question