Perl script required for processing the data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script required for processing the data
# 1  
Old 05-10-2012
MySQL Perl script required for processing the data

I have following result.log file (always has 2 lines) which I need to process,
Code:
cat result.log
name.cmd.method,"result","abc","xyz";
name="hello,mine.12345,"&"tree"&" xyz "&" tree "&" xyz",
data="way,"&" 1"&"rate-me"&"1"&"rate-me",str="",ret="";

now I need to extract the strings/data as below onto a file
Code:
data|name|occurance
way|hello.mine.12345|1
1|tree|2
rate-me|xyz|2

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 05-10-2012 at 11:03 AM..
# 2  
Old 05-10-2012
You say 'always has 2 lines', but I count three.

Can it be depended on to always have the same arrangement?

Which xyz is the one you're wanting? Your example input has that in 3 different places.
# 3  
Old 05-10-2012
Its two lines only, some how when I typed i did newline for second line.
No, I am not after xyz.
Ok to make it clear I will be having data in two fields: DATA and NAME both will be having equal number of strings and each string will be separated by "&".
Now I need NAME|DATA|OCCURRENCE. In DATA and NAME the strings can be repeated multiple times so I need to do duplicate on NAME|DATA and count that write it to FILE.
Code:
NAME|DATA|OCCURRENCE
expect|foo|2
session|major|1
baddata|minor|1

For above data File will be having DATA="foo"&"major"&"foo"&"minor",NAME="expect"&"session"&"expect"&"baddata";

Last edited by Franklin52; 05-12-2012 at 11:15 AM.. Reason: Please use code tags for data and code samples, thank you
# 4  
Old 05-11-2012
How about this ?
Code:
#!/usr/bin/perl

while (<DATA>) {
        chomp;
        @fields=split(/,/);

        @D=split(/=/,$fields[0]);
        @N=split(/=/,$fields[1]);

        @N_V=split(/\&/,$N[1]);
        @D_V=split(/\&/,$D[1]);

        for($i=0;$i<=$#D_V;$i++) {
                $N_V[$i]=~s/"//g;
                $D_V[$i]=~s/"//g;
                $has_d{$N_V[$i]}++;
                $has_n{$N_V[$i]}=$D_V[$i];
        }
}

print "NAME|DATA|OCCURRENCE \n";
foreach (keys %has_n)
{
        print "$_ | $has_n{$_} | $has_d{$_} \n";
}


__DATA__
DATA="foo"&"major"&"foo"&"minor",NAME="expect"&"session"&"expect"&"baddata"

# 5  
Old 05-11-2012
Quote:
Originally Posted by perlDiva
Its two lines only, some how when I typed i did newline for second line.
What's your actual data look like then?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Perl Script:how to find how many parameters are required to run the script

How to find how many parameters are required to run a Perl script? (1 Reply)
Discussion started by: Lakshman_Gupta
1 Replies

2. Shell Programming and Scripting

How do I put data piped to my script into an array for repeated processing

Hi folks, Sorry for something I'm sure was answered already, I just could not find it in a search of the forums. I am trying to build a script that eats a config file as: cat file.cnf | ConProcess.shWhat I want to do inside the script is: !#/usr/bin/bash # captured piped cat into an... (6 Replies)
Discussion started by: Marc G
6 Replies

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

4. Shell Programming and Scripting

perl script processing error

open(IN,"input_file") or die "Can't open Input file.\n"; while (<IN>) { chomp; $line = $_; if($line != '') { print "\nprocessing $line\n"; $size = 0; $hrid = $line; @project_id_array = null; $size = @project_id_array;... (3 Replies)
Discussion started by: vishwakar
3 Replies

5. Shell Programming and Scripting

How to filter required data from file using bash script?

Hi All , I have one file like below , Owner name = abu2-kxy-m29.hegen.app Item_id = AX1981, special_id = *NULL*, version = 1 Created = 09/01/2010 12:56:56 (1283389016) Enddate = 03/31/2011 00:00:00 (1301554800) From the above file I need to get the output in the below format ,i need... (3 Replies)
Discussion started by: gnanasekar_beem
3 Replies

6. Shell Programming and Scripting

awk script processing data from 2 files

Hi! I have 2 files containing data that I need to process at the same time, I have problems in reading a different number of lines from the different files. Here is an explanation of what I need to do (possibly with an awk script). File "samples.txt" contains data in the format: time_instant... (6 Replies)
Discussion started by: Alice236
6 Replies

7. Shell Programming and Scripting

Perl Script required...

Hi All, Windows Platform. Perl Scripting. I have a file called 'hostnames.txt' contains hostname entries one by one line. Script has to perform the following command for each entry in that file. ovtopofix -G <hostname> Please anybody give me the script on this requirement. Thanks,... (1 Reply)
Discussion started by: ntgobinath
1 Replies

8. Shell Programming and Scripting

Help required with a Csh script to read data from a file

Dears, This is what i want.. I need to read a comma separated text file whose name is config.txt. whose content is like ; bscnara,btserrr bscsana,btssanacity ..... i need to read the first string and second string and use it to execute a another shell script. This is the logic. ... (1 Reply)
Discussion started by: fizzme
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
Login or Register to Ask a Question