Sponsored Content
Top Forums Shell Programming and Scripting How to get the lines matched of a file in perl? Post 302440904 by vanitham on Thursday 29th of July 2010 12:08:52 AM
Old 07-29-2010
Quote:
Originally Posted by durden_tyler
(1) Why does the second line match the pattern in all cases ? For example, given these values:

Code:
$start = "14:23";
$end = "14:30";

the second line (in red) -

Code:
14:23:00,14:25:16,0,0,0
14:25:03,14:27:00:16,7,0,0
14:25:00,14:30:16,5,0,0

matches neither the start time (14:25:03 != 14:23) nor the end time (14:27:00 != 14:30).


(2) What is the format of the end time in the 2nd line in each case ?

For example, consider this end time in 2nd line (in red):

Code:
14:23:00,14:25:16,0,0,0
14:25:03,14:27:00:16,7,0,0
14:25:00,14:30:16,5,0,0

That's not HH:MM:SS format, because of the :16 after 00.

Code:
14:27:00:16
HH:MM:SS:??

Should it not be like so ?

Code:
14:23:00,14:25:16,0,0,0
14:25:03,14:27:00,16,7,0,0
14:25:00,14:30:16,5,0,0

tyler_durden
Hi,

If we consider as above:
Code:
14:23:00,14:25:16,0,0,0
14:25:03,14:27:00,16,7,0,0
14:25:00,14:30:16,5,0,0

How can we get the lines and add up the values?

Regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed grep the first matched lines

Hi I have a myfile.txt contains the following: CONTEXT { AAAAA } ... CONTEXT { BBBBB } I want to extract the lines in between CONTEXT { ... }, one by one. Hence I wrote a command like the following, sed -n '/^CONTENT/,/^}/ { w a.txt }' myfile.txt The problem with this... (5 Replies)
Discussion started by: hezjing
5 Replies

2. Shell Programming and Scripting

Get all the values matched in perl

HI, I have sentences like this: @str=("An ribonucleic acid (RNA)-binding protein, started its expression in the daughter cells","Elucidation of the mechanism of retinal degeneration of RNA-binding protein","Rna binding protein is an important protein","In the retinal degenerative process... (1 Reply)
Discussion started by: vanitham
1 Replies

3. Shell Programming and Scripting

Get header and its matched value in perl?

Hi, I have the file contents: Start,End,Req,Resp 12:39,12:40,4,5 The sting to be matched is: Req and Resp. parsefile("Req,Resp"); Here is the code. sub parsefile ($) { $header=shift; (2 Replies)
Discussion started by: vanitham
2 Replies

4. Shell Programming and Scripting

removing lines around a matched pattern

I have an ugly conf file that has the string I'm interested in searching for in the middle of a block of code that's relevant, and I'm trying to find a way to remove that entire block based on the matched line. I've googled for this problem, and most people helping are only interested in... (9 Replies)
Discussion started by: tamale
9 Replies

5. Shell Programming and Scripting

How to find the matched numbers between 2 text file using perl program??

hi dudes, I nee you kind assistance, I have to find the matched numbers from 2 text files and output of matched numbers should be in another text file.. I do have text files like this , for example File 1 787 665*5-p 5454 545-p 445-p 5454*-p File 2 5455 787 445-p 4356 2445 144 ... (3 Replies)
Discussion started by: sureshraj
3 Replies

6. Linux

Perl program to print previous set of lines once a pattern is matched

Hi all, I have a text data file. My aim here is to find line called *FIELD* AV for every record and print lines after that till *FIELD* RF. But here I want first 3 to four lines for very record as well. FIELD AV is some where in between for very record. SO I am not sure how to retrieve lines in... (2 Replies)
Discussion started by: kaav06
2 Replies

7. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

8. Shell Programming and Scripting

Delete lines and the first pattern between 2 matched patterns

Hi, i need help to delete all the lines between 2 matched patterns and the first pattern must be deleted too. sample as follows: inputfile.txt >kump_1 ........................... ........................... >start_0124 dgfhghgfh fgfdgfh fdgfdh >kump_2 ............................. (7 Replies)
Discussion started by: redse171
7 Replies

9. UNIX for Dummies Questions & Answers

Extracting the two lines where the first line is matched

Hi, If I have a file of something like @hg19_gold_AL122127.6-131160 GCTTCATCATGCATGGATAGGCTGGCGCCTTTCCTGAGGCCATATGCCGATGGATATG @hg19_gold_AL122127.6-131159 CTTTAATATTTCCGCCACCATCCTGAGTGAATCCCAGCAAGGACAGTCTTTGGGGATT @hg19_gold_AL122127.6-131158... (4 Replies)
Discussion started by: jyu429
4 Replies

10. Shell Programming and Scripting

Find all matched lines from two files

Hello, everyone I have two files like this: File 1: A B C D E FFile 2:A B 1 A C 2 A K 3 B A 4 D E 3 W X 2 A B 2I want to print all lines (file2) that the first two columns are consist of elements from file1. So, what I expected is : A B 1 A B 2 (2 Replies)
Discussion started by: nengcheng
2 Replies
LOCALTIME(3)								 1							      LOCALTIME(3)

localtime - Get the local time

SYNOPSIS
array localtime ([int $timestamp = time()], [bool $is_associative = false]) DESCRIPTION
The localtime(3) function returns an array identical to that of the structure returned by the C function call. PARAMETERS
o $timestamp - The optional $timestamp parameter is an integer Unix timestamp that defaults to the current local time if a $timestamp is not given. In other words, it defaults to the value of time(3). o $is_associative - If set to FALSE or not supplied then the array is returned as a regular, numerically indexed array. If the argument is set to TRUE then localtime(3) returns an associative array containing all the different elements of the structure returned by the C func- tion call to localtime. The names of the different keys of the associative array are as follows: o "tm_sec" - seconds, 0 to 59 o "tm_min" - minutes, 0 to 59 o "tm_hour" - hours, 0 to 23 o "tm_mday" - day of the month, 1 to 31 o "tm_mon" - month of the year, 0 (Jan) to 11 (Dec) o "tm_year" - years since 1900 o "tm_wday" - day of the week, 0 (Sun) to 6 (Sat) o "tm_yday" - day of the year, 0 to 365 o "tm_isdst" - is daylight savings time in effect? Positive if yes, 0 if not, negative if unknown. ERRORS
/EXCEPTIONS Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the $TZ environment variable. See also date_default_timezone_set(3) CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | Now issues the E_STRICT and E_NOTICE time zone | | | errors. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 localtime(3) example <?php $localtime = localtime(); $localtime_assoc = localtime(time(), true); print_r($localtime); print_r($localtime_assoc); ?> The above example will output something similar to: Array ( [0] => 24 [1] => 3 [2] => 19 [3] => 3 [4] => 3 [5] => 105 [6] => 0 [7] => 92 [8] => 1 ) Array ( [tm_sec] => 24 [tm_min] => 3 [tm_hour] => 19 [tm_mday] => 3 [tm_mon] => 3 [tm_year] => 105 [tm_wday] => 0 [tm_yday] => 92 [tm_isdst] => 1 ) SEE ALSO
getdate(3). PHP Documentation Group LOCALTIME(3)
All times are GMT -4. The time now is 02:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy