Perl file processing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl file processing
# 1  
Old 10-14-2009
Perl file processing

I have an input array like :

"SVR1" GRP="EVT_BOX06B" SRID=100 MIN=2
"SVR1" GRP="EVT_BOX06B" SRID=200 MIN=1
"SVR2" GRP="ADM_BOX06B" SRID=100 MIN=1
"SVR1" GRP="EVT_BOX88B" SRID=100 MIN=2
"SVR1" GRP="EVT_BOX88B" SRID=200 MIN=1
"SVR2" GRP="ADM_BOX88B" SRID=100 MIN=1

I need to get final output as below :

SVR1 EVT_BOX06B 100 3
SVR2 ADM_BOX06B 100 1
SVR1 EVT_BOX88B 100 3
SVR2 ADM_BOX88B 100 1

The last column in the output is the total count only if the first column & second column are same.

Thanks in advance.
# 2  
Old 10-14-2009
Code:
while(<>)  {
    /"([^"]*)"[^"]*"([^"]*).*?(\d+).*?(\d+)/;
    $hash{$1 . '#' . $2}++;
    $hash1{$1} = $3;
}

while (($key, $value) = each %hash)  {
    @tmp = split (/#/, $key);
    print "$tmp[0] $tmp[1] $hash1{$tmp[0]} $value\n"; 
}

As expected.,
Code:
$ perl t.pl t1
SVR2 ADM_BOX06B 100 1
SVR1 EVT_BOX88B 200 2
SVR1 EVT_BOX06B 200 2
SVR2 ADM_BOX88B 100 1

# 3  
Old 10-15-2009
Thanks for that piece of code. However, looks like there's some misunderstanding the in the expected output which I have mentioned. The final column is the count of MIN value with same first & second column. For ex.,
"SVR1" GRP="EVT_BOX06B" SRID=100 MIN=2
"SVR1" GRP="EVT_BOX06B" SRID=200 MIN=1

the output should be
SVR1 EVT_BOX06B 3
# 4  
Old 10-15-2009
Code:
sed -e 's/[^ ]*=//g' -e 's/"//g'

# 5  
Old 10-15-2009
Thanks summer_cherry, but this code does not add up the last column if values of 1st & 2nd columns are same.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

2. Shell Programming and Scripting

PARALLEL PROCESSING IN PERL

HI All, I have scenerio where I need to call sub modules through for loop for (i=0; i<30 ;i++) { .. .. .. subroutine 1; subroutine 2; } I want this to be run in parallel process1 { ... ... subroutine 1; subroutine 2; (0 Replies)
Discussion started by: gvk25
0 Replies

3. Shell Programming and Scripting

perl problem in processing excel file

Dear all, I got a perl script to write some data into an excel file using Spreadsheet::ParseExcel::SaveParser. After that I find all formulas in the excel file are gone. Does any body encounter this problem or have any work around? (2 Replies)
Discussion started by: eldonlck
2 Replies

4. Programming

help me with perl script xml processing

Hi everyone, I have Xml files in a folder, I need to extract some attribute values form xml files and store in a hash. My xml file look like this. <?xml version="1.0" encoding="UTF-8"?> <Servicelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"... (0 Replies)
Discussion started by: pavani reddy
0 Replies

5. UNIX for Advanced & Expert Users

perl text file processing using hash

Hi Experts, I have this requirement to process large files (200MB+).Format of files is like: recordstart val1 1 val2 2 val3 4 recordstart val1 5 val2 6 val3 1 val4 1 recordstart val1 ... (4 Replies)
Discussion started by: mtomar
4 Replies

6. Shell Programming and Scripting

Processing a file in perl

Qspace ABC Queue doCol: true Queue order: fifo Queue setCol: red Queue order: fifo Qspace XYZ Queue getCol: true Queue order: fifo I need to append every line in this file with Qspace & Queue, so that final o/p shall look like this, Qspace: ABC Queue: doCol Qspace: ABC Queue: doCol... (2 Replies)
Discussion started by: deo_kaustubh
2 Replies

7. Shell Programming and Scripting

Simple Script needed for Processing CSV file perl

I am new to perl, and need a script to pull a CSV file, strip out 2 leading columns, and 2 ending columns, and resave the file in a new location. The file is basic and has less than 10,000 records. Secondly, can I schedule perl scripts to run daily? Can someone provide the basic script to... (1 Reply)
Discussion started by: cobbjob
1 Replies

8. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

9. Shell Programming and Scripting

perl script for file processing

Aim: To scan a file and ignore all characters that has an ASCII value from 0 to 31 and 127 to 255 and accept only those characters having an ASCII between 32 and 126. Script: #!/usr/local/bin/perl $filename = "$ARGV"; if (-e $filename) { open(OUT, "${filename}") || die "can't... (10 Replies)
Discussion started by: SEEHTAS
10 Replies

10. Shell Programming and Scripting

File processing on perl

Hey everyone ... I wanted to process the contents of a file, as in modify its contents. whats the best way to do it on perl? In more detail I hav to go through the contents of the file, match patterns n then modify the contents of the same file depending on the matching results. Any help is... (2 Replies)
Discussion started by: garric
2 Replies
Login or Register to Ask a Question