How to get the latest and new values from the file in perl?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the latest and new values from the file in perl?
# 1  
Old 08-13-2010
How to get the latest and new values from the file in perl?

Hi,

I have a file with these following contents..

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0

I am not able to get the last value and current value.

After some process the above file gets appended with new count vaule...

Now the recent contents of the file are:

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0
Aug13 2010 04:07:55,Aug13 2010 04:08:55,1,0,0,0
Aug13 2010 04:10:55,Aug13 2010 04:13:55,2,0,0,0

I have to compare the value before and after run i.e just check the values in file before running and after some process those values get incremented.

I have to compare those values.

How can i do it perl?




Any suggestions?

Regards

Last edited by pludi; 08-13-2010 at 02:44 PM.. Reason: fixed code tag
# 2  
Old 08-13-2010
Quote:
Originally Posted by vanitham
...
Now the recent contents of the file are:

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0
Aug13 2010 04:07:55,Aug13 2010 04:08:55,1,0,0,0
Aug13 2010 04:10:55,Aug13 2010 04:13:55,2,0,0,0

I have to compare the value before and after run i.e just check the values in file before running and after some process those values get incremented.

I have to compare those values.

How can i do it perl?
...
Your question is not clear.

Let's assume that your file looked like this before the process run -

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0

And it looks like this after the process run -

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0
Aug13 2010 04:07:55,Aug13 2010 04:08:55,1,0,0,0
Aug13 2010 04:10:55,Aug13 2010 04:13:55,2,0,0,0

(1) There were 4 records before the process run. They are in red color.
(2) The process appended 2 new records to the file. They are in blue color.
(3) There are 6 records now, after the process run.

Quote:
I have to compare those values.
How can i do it perl?
What exactly do you want to compare ??
There are 4 + 2 = 6 records in the file. Each record has a bunch of fields.

Why not take the file shown above as your input and show us your expected output ? Please put it within [ code ] tags.

tyler_durden
# 3  
Old 08-15-2010
Quote:
Originally Posted by durden_tyler
Your question is not clear.

Let's assume that your file looked like this before the process run -

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0

And it looks like this after the process run -

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0
Aug13 2010 04:07:55,Aug13 2010 04:08:55,1,0,0,0
Aug13 2010 04:10:55,Aug13 2010 04:13:55,2,0,0,0

(1) There were 4 records before the process run. They are in red color.
(2) The process appended 2 new records to the file. They are in blue color.
(3) There are 6 records now, after the process run.



What exactly do you want to compare ??
There are 4 + 2 = 6 records in the file. Each record has a bunch of fields.

Why not take the file shown above as your input and show us your expected output ? Please put it within [ code ] tags.

tyler_durden
Hi,

Thanks for the reply.

The file contents before the process is as shown below:

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0

so the last output will be the last line or more Precisely the last line of the file (i.e last entry in the file) so the output is:
Code:
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0

After some process is done the entries in the file get changed.

Code:
StartTimeStamp,EndTimeStamp,Counter1,Counter2,Counter3,Counter4
Aug13 2010 02:49:21,Aug13 2010 02:54:21,9,8,0,0
Aug13 2010 02:59:32,Aug13 2010 03:00:00,0,0,0,0
Aug13 2010 03:00:00,Aug13 2010 03:04:32,9,8,0,0
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0
Aug13 2010 04:07:55,Aug13 2010 04:08:55,1,0,0,0
Aug13 2010 04:10:55,Aug13 2010 04:13:55,2,0,0,0

After the process what are the new entries in the file i have to check it. Here in this case Output is:
Code:
Aug13 2010 04:07:55,Aug13 2010 04:08:55,1,0,0,0
Aug13 2010 04:10:55,Aug13 2010 04:13:55,2,0,0,0

once this is done i need to split the array and get the values of Counter1,Counter2,Counter3,Counter4.

Basicaly i want to check for the new and old entries in perl.

This procedure how can i do it in perl?

Regards
Vanitha
# 4  
Old 08-16-2010
Quote:
Originally Posted by vanitham
...
After the process what are the new entries in the file i have to check it. Here in this case Output is:
Code:
Aug13 2010 04:07:55,Aug13 2010 04:08:55,1,0,0,0
Aug13 2010 04:10:55,Aug13 2010 04:13:55,2,0,0,0

once this is done i need to split the array and ...
What array do you refer to here? Two records have been added to your file as seen above. Where's the array ?

Quote:
Basicaly i want to check for the new and old entries in perl.
If I understood correctly, the "old" entry is the following -

Code:
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0

What's the new entry ?

tyler_durden
# 5  
Old 08-17-2010
Quote:
Originally Posted by durden_tyler
What array do you refer to here? Two records have been added to your file as seen above. Where's the array ?



If I understood correctly, the "old" entry is the following -

Code:
Aug13 2010 03:07:55,Aug13 2010 03:08:55,0,0,0,0

What's the new entry ?

tyler_durden
Hi,

Thanks for the reply.

From the file i am taking the contents and putting in an array so thats the reason i mentioned array.

Basically i need to identify new and old values from the file(i.e new entries and old entries from file)

Regards
Vanitha
# 6  
Old 08-17-2010
Something like this...I assums you can do the required split function after identification of new lines...

Code:
#!/usr/bin/perl -w

open(FILE,"<old") || die "error opening file:$!\n";

@lines = <FILE>;
close(FILE);
$numLines = scalar @lines;

## Do all process here..The one below is sample..
`echo "Aug13 2010 03:07:55,Aug13 2010 03:09:55,0,1,1,0" >> ./old`;
#
#
#read the file to read the contents for changes

open(FILE,"<old") || die "error opening file:$!\n";
@lines = <FILE>;
close(FILE);
for($line=$numLines;$line< scalar @lines;$line++) {
   print "New Line = $lines[$line]";
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get multiple values from an xml file using one of the following commands or together awk/perl/script

Hello, I have a requirement to extract the value from multiple xml node and print out the values to new file to compare. Would be done using either awk/perl or some unix script. For example sample input file: ..... ..... <factories xmi:type="resources.jdbc:DataSource"... (2 Replies)
Discussion started by: slbmind
2 Replies

2. Shell Programming and Scripting

Perl: Writing table values to a file

I have a file like this, 1,a,saurav 2,b,rout I want to show this file in a perl cgi page table and want to add a column which will contain a text box. There I will give some manual input, which will be written to the existing file(or a new file) in below format. 1|a|saurav|bangalore... (2 Replies)
Discussion started by: sauravrout
2 Replies

3. Shell Programming and Scripting

Perl : copying only the latest file to other directory

In linux.. In a directory there are 3 files which I want to copy only the latest file (ls -ltr myfiles*.txt|tail -1) to other directory in perl? Could anyone please help me with the code? Regards, J (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

5. Shell Programming and Scripting

AWK, Perl or Shell? Unique strings and their maximum values from 3 column data file

I have a file containing data like so: 2012-01-02 GREEN 4 2012-01-02 GREEN 6 2012-01-02 GREEN 7 2012-01-02 BLUE 4 2012-01-02 BLUE 3 2012-01-02 GREEN 4 2012-01-02 RED 4 2012-01-02 RED 8 2012-01-02 GREEN 4 2012-01-02 YELLOW 5 2012-01-02 YELLOW 2 I can't always predict what the... (4 Replies)
Discussion started by: rich@ardz
4 Replies

6. UNIX for Dummies Questions & Answers

extracting values from file using perl

I would like to read value after $ symbol from a file. For eg a file will be having the following lines. 5,$0,-32768p,32767p,$400014f8,1,, 5,$0,0,0,$400008ce,1,, 5,$0,0,0,$400008d0,1,, i would like to read 400014f8 then 400014f8 and similar all the value after $ symbol.Can any one help... (1 Reply)
Discussion started by: jagadeeshrr
1 Replies

7. Shell Programming and Scripting

Perl matching values in a file

I am trying to match first 5 values of $passt variable in a file $chpdvlst and then verify that value in $grp parameter I want first 5 values which has $vaht - ship and $grp = N-grp. Somehow script below lists whole file. $memcnt = 5; $passt = ship; open (ADVOUT, "< $chpdvlst") || die... (5 Replies)
Discussion started by: dynamax
5 Replies

8. Shell Programming and Scripting

Perl's buffered I/O is causing me to miss latest log file entries in log colorizer. How to fix?

I've been finding myself using a log file colorizer written in perl to reformat and colorize the output from many different programs. Mainly, however, I use it to make the output from "tail -f" commands more readable. The base perl script I use is based on "colorlogs.pl" available from the... (1 Reply)
Discussion started by: rcsteiner
1 Replies

9. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies

10. Shell Programming and Scripting

PERL:How to convert numeric values txt file to PACKED DECIMAL File?

Is there any way to convert numeric values txt file to PACKED DECIMAL File using PERL. Regards, Alok (1 Reply)
Discussion started by: aloktiwary
1 Replies
Login or Register to Ask a Question