Re: regex matching statements

2024-06-19 Thread Levi Elias Nystad-Johansen via beginners
Hi, 

Yes, they are the same. 

I like to use $_ only when the data comes in $_ naturally. Like in a for loop: 
for (qw< abc >)
{
  if ( !/\w+\d+/ )
  {
print "not matched";
  }
}

Otherwise, I have to write $_, then I prefer to name the variable something 
descriptive instead. 
Makes the code more readable and maintainable down the road. 


-L 


On Wednesday, June 19th, 2024 at 3:55 AM, Jeff Peng via beginners 
 wrote:

> Hello list,
> 
> are these statements the same in perl?
> 
> $ perl -le '$_="abc";if (!/\w+\d+/){print "not matched"}'
> not matched
> 
> $ perl -le '$_="abc";if ($_ !~ /\w+\d+/){print "not matched"}'
> not matched
> 
> or which is the better one?
> 
> Thanks.
> 
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




regex matching statements

2024-06-18 Thread Jeff Peng via beginners

Hello list,

are these statements the same in perl?

$ perl -le '$_="abc";if (!/\w+\d+/){print "not matched"}'
not matched

$ perl -le '$_="abc";if ($_ !~ /\w+\d+/){print "not matched"}'
not matched

or which is the better one?

Thanks.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex

2024-01-24 Thread karl
Mike:
> I stand properly scolded.

I didn't want to scold anyone, it seems I expressed myself wrong.
Sorry for that.

Regards,
/Karl Hammar


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex

2024-01-23 Thread Mike



I stand properly scolded.


Mike


On 1/23/24 07:01, k...@aspodata.se wrote:

Please stop using my mail address when replying, I'm on the list and
don't want two copies of the same mail (it's not about you Mike).



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex

2024-01-23 Thread karl
Please stop using my mail address when replying, I'm on the list and
don't want two copies of the same mail (it's not about you Mike).

Mike 
> Why is my Perl not working on that command?
> 
> $ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
> Unescaped left brace in regex is illegal here in regex; marked by <-- 
> HERE in m/a{ <-- HERE ,2}/ at -e line 1.
> $
> 
> But this works:
> $ perl -e 'exit(10) if "aaa"=~/a{0,2}/;'
> $
> 
> $ echo $?
> 10
> $

 On an old debian woody box I get:
$ perl -v | grep v5
This is perl, v5.6.1 built for i386-linux
$ perl -e 'exit(10) if "aaa"=~/a{,2}/;'; echo $?
0
$ perl -e 'exit(10) if "aaa"=~/a{0,2}/;'; echo $?
10

$ man perlre
...
   The following standard quantifiers are recognized:

   *  Match 0 or more times
   +  Match 1 or more times
   ?  Match 1 or 0 times
   {n}Match exactly n times
   {n,}   Match at least n times
   {n,m}  Match at least n but not more than m times
...

 So, old perl versions don't have the {,m} quantifier, check your 
documentation for that. The easy way out is to always use {0,m} instead 
of {,m}, which is the same thing in modern perl, actually there is no
need ever to use the {,m} quantifier.

I don't know why I don't get a perl error message above, maybe a bug.

///

 On a more uptodate system I get:
$ perl -v | grep v5
This is perl 5, version 34, subversion 1 (v5.34.1) built for 
x86_64-linux-thread-multi
$ perl -e 'exit(10) if "aaa"=~/a{,2}/;'; echo $?
10
$ perl -e 'exit(10) if "aaa"=~/a{0,2}/;'; echo $?
10

///

 If you are interested of the syntax rules, check under "Simple 
statements" in:

 (perl 5.6.1)
$ man perlsyn
   Any simple statement may optionally be followed by a SIN-
   GLE modifier, just before the terminating semicolon (or
   block ending).  The possible modifiers are:

   if EXPR
   unless EXPR
   while EXPR
   until EXPR
   foreach EXPR

...

 (perl 5.34.1)
$ man perlsyn
...
   Statement Modifiers
   Any simple statement may optionally be followed by a SINGLE modifier,
   just before the terminating semicolon (or block ending).  The possible
   modifiers are:

   if EXPR
   unless EXPR
   while EXPR
   until EXPR
   for LIST
   foreach LIST
   when EXPR

...

So, modern perl also have "for" and "when".

///

Also note that in a compound statement you have to ()'ize the EXPR as in

 if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK

in contrast to for the modifier you don't need to:

 STATEMENT if EXPR;

I prefer to always to use ()' around the expression, since it makes it 
easier to convert between the two forms.

Regards,
/Karl Hammar



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex

2024-01-22 Thread Mike


Why is my Perl not working on that command?

$ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
Unescaped left brace in regex is illegal here in regex; marked by <-- 
HERE in m/a{ <-- HERE ,2}/ at -e line 1.

$

But this works:
$ perl -e 'exit(10) if "aaa"=~/a{0,2}/;'
$

$ echo $?
10
$

It sure surprised me that the first one did not work for me.

Do I need to upgrade my Perl?
$ perl -v

This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux
(with 1 registered patch, see perl -V for more detail)
snip
$

I just went through my Perl documentation and none of
it allows {,2}.  Learning Perl Second Edition (July 1997)
says:
"If you leave off the second number, as in /x{5,}/, it means "that many 
or more" (five or more in this case), and if you leave off the comma, as 
in /x{5}/, it means "exactly this many" (five x's).

To get five or less x's, you must put the zero in, as in /x{0,5}/."


Mike


On 1/22/24 06:23, Jorge Almeida wrote:

Please help me to understand this:
$ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
$ echo $?
$ 10

Thanks

Jorge Almeida




Re: regex

2024-01-22 Thread armando perez pena
Hi,

Sometimes the large path is the shortest one. Go through the tutorial in Perl 
for regular expressions and you will solve your questions and you will learn a 
lot.

About regular expressions are two points of view. First one says that you must 
learn and use it.

The other point of is: if you have a problem and you say I will solve it with 
regular expressions then you have two problems.

Ánimos!
Saludos

From: Claude Brown via beginners 
Sent: Monday, January 22, 2024 10:49:50 PM
To: k...@aspodata.se ; beginners@perl.org 
Subject: RE: regex

Jorge,

Expanding on Karl's answer (and somewhat labouring his point) consider these 
examples:

$a =~ /Jorge/
$a =~ /^Jorge/
$a =~ /Jorge$/
$a =~ /^Jorge$/

This shows that regex providing four different capabilities:
- detect "Jorge" anywhere in the string
- detect "Jorge" at the start of a string (by adding ^)
- detect "Jorge" at the end of a string (by adding $)
- detect that the string is exactly "Jorge" (both ^ and $)

Replace "Jorge" with your pattern, and the result is the same.

Cheers,

Claude.





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: regex

2024-01-22 Thread Claude Brown via beginners
Jorge,

Expanding on Karl's answer (and somewhat labouring his point) consider these 
examples:

$a =~ /Jorge/
$a =~ /^Jorge/
$a =~ /Jorge$/
$a =~ /^Jorge$/

This shows that regex providing four different capabilities:
- detect "Jorge" anywhere in the string
- detect "Jorge" at the start of a string (by adding ^)
- detect "Jorge" at the end of a string (by adding $)
- detect that the string is exactly "Jorge" (both ^ and $)

Replace "Jorge" with your pattern, and the result is the same.

Cheers,

Claude.





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex

2024-01-22 Thread Levi Elias Nystad-Johansen via beginners
I agree that this is confusing, and I think many resources describing regex in 
unhelpful ways is partly to blame.
descriptions like "pattern that matches against a string" and similar.

this implies that a regex has to match the string, but this is not the case.
a regex does not have to match the string, instead the string has to satisfy 
the regex.

"aaa" satisfies /a{,2}/ because it contains everything the regex requires.
thinking of regex in this way has been a help to me atleast 

-L

 Original Message 
On 22. jan. 2024, 13:23, Jorge Almeida wrote:

> Please help me to understand this:
> $ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
> $ echo $?
> $ 10
>
> Thanks
>
> Jorge Almeida

Re: regex

2024-01-22 Thread Andy Bach
Yes, the {}l RE modifier has the canonical form
{a,b} where a and b are numbers and so that modifies the char before it to
match from a to b times, e,g
A{1,3}

matches one, two or three As.  If you leave out the first number, zero is
presumed. Hmm, perl 5.30
% perl -E 's ay(10) if "aaa"=~/a{,2}/;'
Unescaped left brace in regex is illegal here in regex; marked by <-- HERE
in m/a{ <-- HERE ,2}/ at -e line 1.

and
% perldoc perlre

says
   Quantifiers
Quantifiers are used when a particular portion of a pattern needs to
match a certain number (or numbers) of times. If there isn't a
quantifier the number of times to match is exactly one. The following
standard quantifiers are recognized:

*   Match 0 or more times
+   Match 1 or more times
?   Match 1 or 0 times
{n} Match exactly n times
{n,}Match at least n times
{n,m}   Match at least n but not more than m times

(If a non-escaped curly bracket occurs in a context other than one of
the quantifiers listed above, where it does not form part of a
backslashed sequence like "\x{...}", it is either a fatal syntax error,
or treated as a regular character, generally with a deprecation warning
raised. To escape it, you can precede it with a backslash ("\{") or
enclose it within square brackets ("[{]"). This change will allow for
future syntax extensions (like making the lower bound of a quantifier
optional), and better error checking of quantifiers).

On Mon, Jan 22, 2024 at 6:59 AM  wrote:

> Jorge Almeida:
> > Please help me to understand this:
> > $ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
> > $ echo $?
> > $ 10
>
> In man perlre, under "Regular Expressions" it says:
>
>   {,n}Match at most n times
>
> So /a{,2}/ matches "", "a", and "aa" and is ignorant about what
> comes before and after (basically). That "aa" is followed by a
> "a" isn't something the expression prohibits. If you want that
> try /^a{,2}$/ instead.
>
> Regards,
> /Karl Hammar
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: regex

2024-01-22 Thread karl
Jorge Almeida:
> On Mon, 22 Jan 2024 at 13:00,  wrote:
> > Jorge Almeida:
> > > $ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
...
> >   {,n}Match at most n times
...
> Yes, I read it (several times). I still don't understand it (I understand
> what you're saying, and I trust you're right, I just don't understand how
> this behaviour matches the description above--- "at most", really?)

Just think it like this:
 on the table there is three diamonds,
 can you find zero, one, or preferable two diamonds there ?
...
> Now, in
> perl -e 'print $1,"\n" if "aaa"=~/(a{,2})/;'
> $ aa
> this is understandable. More or less. Maybe the semantics of /a{,2}/ should
> be described as "match any number of consecutive 'a' whatsoever and capture
> at most 2  'a' characters...

No, it just looks at the first two a's and finds a match, there is 
still one "a" left, but who cares, you have already got your match.

Regards,
/Karl Hammar



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex

2024-01-22 Thread karl
Jorge Almeida:
> Please help me to understand this:
> $ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
> $ echo $?
> $ 10

In man perlre, under "Regular Expressions" it says:

  {,n}Match at most n times

So /a{,2}/ matches "", "a", and "aa" and is ignorant about what 
comes before and after (basically). That "aa" is followed by a
"a" isn't something the expression prohibits. If you want that
try /^a{,2}$/ instead.

Regards,
/Karl Hammar



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




regex

2024-01-22 Thread Jorge Almeida
Please help me to understand this:
$ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
$ echo $?
$ 10

Thanks

Jorge Almeida


Re: escape character in regex

2022-10-10 Thread John W. Krahn

On 2022-10-10 18:12, Henrik Park wrote:


I know "/" is a special character for regex, which should be escaped.

But if I put "/" in a variable and use the variable in regex, then it 
doesn't need the explicit escape. Like this one:


$ perl -le '$delimiter="/"; $str="hello/world/buddy"; 
@list=split/$delimiter/,$str;print "@list"'

hello world buddy


Am I right? thank you.




"/" is NOT a special charater in a regular expression.  It is just that 
in Perl the default delimiter for some operators is "/" (i.e. m//, s///, 
tr///, etc.).


John

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




escape character in regex

2022-10-10 Thread Henrik Park

Hello

I know "/" is a special character for regex, which should be escaped.

But if I put "/" in a variable and use the variable in regex, then it 
doesn't need the explicit escape. Like this one:


$ perl -le '$delimiter="/"; $str="hello/world/buddy"; 
@list=split/$delimiter/,$str;print "@list"'

hello world buddy


Am I right? thank you.


--
Simple Mail
https://simplemail.co.in/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: about a regex

2021-12-31 Thread wagsworld48 via beginners
Add ^ as
[^a-zA-Z0-9]

Though there are probably a number of different ways to approach RegEx…

Wags ;)
WagsWorld
Hebrews 4:15
Ph(primary) : 408-914-1341
Ph(secondary): 408-761-7391
On Dec 31, 2021, 20:22 -0800, Piper H , wrote:
> Hello
>
> I know [a-zA-Z0-9] means words and numbers.
> But what's the reverse of this regex?
>
> Thank you.


Re: about a regex

2021-12-31 Thread Piper H
I queried the doc and found this is what I wanted.
[^a-zA-Z0-9]

Thank you.

On Sat, Jan 1, 2022 at 12:38 PM Adam Hopkins 
wrote:

> If you add an underscore (the equivalent of \w): [a-zA-Z0-9*_*]
>
> Then \W is the opposite.
>
>
> If you wanted to not match [a-zA-Z0-9]
>
> You could do
>
> $string !~ m/[a-zA-Z0-9]/
>
>
> On Fri, Dec 31, 2021 at 10:23 PM Piper H  wrote:
>
>> Hello
>>
>> I know [a-zA-Z0-9] means words and numbers.
>> But what's the reverse of this regex?
>>
>> Thank you.
>>
>


Re: about a regex

2021-12-31 Thread Adam Hopkins
If you add an underscore (the equivalent of \w): [a-zA-Z0-9*_*]

Then \W is the opposite.


If you wanted to not match [a-zA-Z0-9]

You could do

$string !~ m/[a-zA-Z0-9]/


On Fri, Dec 31, 2021 at 10:23 PM Piper H  wrote:

> Hello
>
> I know [a-zA-Z0-9] means words and numbers.
> But what's the reverse of this regex?
>
> Thank you.
>


about a regex

2021-12-31 Thread Piper H
Hello

I know [a-zA-Z0-9] means words and numbers.
But what's the reverse of this regex?

Thank you.


Re: Regex to detect natural language fragment

2021-09-14 Thread Julius Hamilton
 Thanks very much.

@Chankey Pathak, which of those libraries does you recommend for this task?

Best regards,
Julius

On Tue, Sep 14, 2021 at 2:33 AM Ken Peng  wrote:

> Or use GPT-3 who has a free online API.
> https://openai.com/blog/openai-api/
>
> regards
>
> On Mon, Sep 13, 2021 at 11:42 PM Chankey Pathak 
> wrote:
>
>> You can look into NLP https://metacpan.org/search?q=nlp
>>
>> On Mon, 13 Sept 2021 at 21:04, Julius Hamilton <
>> juliushamilton...@gmail.com> wrote:
>>
>>> Hey,
>>>
>>> I'm not sure if this is possible, and if it's not, I'll explore a better
>>> way to do this.
>>>
>>> I would like to write a script which analyzes if a line of text is
>>> (likely) a broken natural language sentence, i.e., it is probably part of a
>>> sentence, even if the start or end is not present, rather than it being a
>>> fully "complete" linguistic entity, for example, a header of a section,
>>> which does not have a period at the end and is not really a sentence, yet
>>> is in a complete and unbroken form.
>>>
>>> I'm pretty sure in principle this will require some kind of syntax
>>> parsing. I think I read somewhere regular expressions for some mathematical
>>> reason cannot parse tree / nested structures, for example HTML.
>>>
>>> Does anyone know what some next most ubiquitous, standard tool is for
>>> analyzing nested linguistic structures? Is that an XML parser?
>>>
>>> Thanks very much,
>>> Julius
>>>
>>


Re: Regex to detect natural language fragment

2021-09-13 Thread Ken Peng
Or use GPT-3 who has a free online API.
https://openai.com/blog/openai-api/

regards

On Mon, Sep 13, 2021 at 11:42 PM Chankey Pathak 
wrote:

> You can look into NLP https://metacpan.org/search?q=nlp
>
> On Mon, 13 Sept 2021 at 21:04, Julius Hamilton <
> juliushamilton...@gmail.com> wrote:
>
>> Hey,
>>
>> I'm not sure if this is possible, and if it's not, I'll explore a better
>> way to do this.
>>
>> I would like to write a script which analyzes if a line of text is
>> (likely) a broken natural language sentence, i.e., it is probably part of a
>> sentence, even if the start or end is not present, rather than it being a
>> fully "complete" linguistic entity, for example, a header of a section,
>> which does not have a period at the end and is not really a sentence, yet
>> is in a complete and unbroken form.
>>
>> I'm pretty sure in principle this will require some kind of syntax
>> parsing. I think I read somewhere regular expressions for some mathematical
>> reason cannot parse tree / nested structures, for example HTML.
>>
>> Does anyone know what some next most ubiquitous, standard tool is for
>> analyzing nested linguistic structures? Is that an XML parser?
>>
>> Thanks very much,
>> Julius
>>
>


Re: Regex to detect natural language fragment

2021-09-13 Thread Chankey Pathak
You can look into NLP https://metacpan.org/search?q=nlp

On Mon, 13 Sept 2021 at 21:04, Julius Hamilton 
wrote:

> Hey,
>
> I'm not sure if this is possible, and if it's not, I'll explore a better
> way to do this.
>
> I would like to write a script which analyzes if a line of text is
> (likely) a broken natural language sentence, i.e., it is probably part of a
> sentence, even if the start or end is not present, rather than it being a
> fully "complete" linguistic entity, for example, a header of a section,
> which does not have a period at the end and is not really a sentence, yet
> is in a complete and unbroken form.
>
> I'm pretty sure in principle this will require some kind of syntax
> parsing. I think I read somewhere regular expressions for some mathematical
> reason cannot parse tree / nested structures, for example HTML.
>
> Does anyone know what some next most ubiquitous, standard tool is for
> analyzing nested linguistic structures? Is that an XML parser?
>
> Thanks very much,
> Julius
>


Regex to detect natural language fragment

2021-09-13 Thread Julius Hamilton
Hey,

I'm not sure if this is possible, and if it's not, I'll explore a better
way to do this.

I would like to write a script which analyzes if a line of text is (likely)
a broken natural language sentence, i.e., it is probably part of a
sentence, even if the start or end is not present, rather than it being a
fully "complete" linguistic entity, for example, a header of a section,
which does not have a period at the end and is not really a sentence, yet
is in a complete and unbroken form.

I'm pretty sure in principle this will require some kind of syntax parsing.
I think I read somewhere regular expressions for some mathematical reason
cannot parse tree / nested structures, for example HTML.

Does anyone know what some next most ubiquitous, standard tool is for
analyzing nested linguistic structures? Is that an XML parser?

Thanks very much,
Julius


Re: regex help - only one value returned

2020-12-02 Thread Jim Gibson
In your original example:

print "match1='$1' '$2'\n" if ($T=~/^((mr|mrs|miss|dr|prof|sir) .{5,}?)\n/smi);
print "match2='$1' '$2'\n" if ($T=~/^(mr|mrs|miss|dr|prof|sir .{5,}?)\n/smi);

the interior parentheses in example one terminates the alternation, so the last 
string is ’sir’.

In example two, the alternation is not terminated until the first ‘)', so the 
last string is ’sir .{5,}?’. followed in the regular expression by the “\n” 
character. Since in $T ‘miss’ is not followed by an \n, the match fails. Vlado 
has explained how to group and terminate the alternation without capturing the 
match result.


> On Dec 2, 2020, at 6:08 AM, Gary Stainburn  
> wrote:
> 
> On 02/12/2020 13:56, Vlado Keselj wrote:
>> Well, it seems that the first one is what you want, but you just need to
>> use $1 and ignore $2.
>> 
>> You do need parentheses in '(mr|mrs|miss|dr|prof|sir)' but if you do not
>> want for them to be captured in $2, you can use:
>> '(?:mr|mrs|miss|dr|prof|sir)'.  For example:
>> 
>> print "match3='$1' '$2'\n" if
>> ($T=~/^((?:mr|mrs|miss|dr|prof|sir) .{5,}?)\n/smi);
>> 
>> would give output:
>> 
>> match3='Miss Jayne Doe' ''
> Perfect, thank you.
> 
> I can't ignore $2 as it's in a loop with other regex that genuinely returns 
> multiple matches.  The amendment to the REGEX worked perfectly.

It is always best to save the results of a match with capturing in another 
variable. The capturing variables $1, $2, etc. are not reassigned if a match 
fails, so if you use them after a failed match, they will be the values left 
over from a previous match. So do this:

my $salutation = $1;
my $name = $2;

If you don’t want a possible undefined value, so this instead:

my $name = $2 || '';


Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex help - only one value returned

2020-12-02 Thread Gary Stainburn

On 02/12/2020 13:56, Vlado Keselj wrote:

Well, it seems that the first one is what you want, but you just need to
use $1 and ignore $2.

You do need parentheses in '(mr|mrs|miss|dr|prof|sir)' but if you do not
want for them to be captured in $2, you can use:
'(?:mr|mrs|miss|dr|prof|sir)'.  For example:

print "match3='$1' '$2'\n" if
($T=~/^((?:mr|mrs|miss|dr|prof|sir) .{5,}?)\n/smi);

would give output:

match3='Miss Jayne Doe' ''

Perfect, thank you.

I can't ignore $2 as it's in a loop with other regex that genuinely 
returns multiple matches.  The amendment to the REGEX worked perfectly.


Gary

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex help - only one value returned

2020-12-02 Thread Vlado Keselj


Well, it seems that the first one is what you want, but you just need to 
use $1 and ignore $2.

You do need parentheses in '(mr|mrs|miss|dr|prof|sir)' but if you do not 
want for them to be captured in $2, you can use:
'(?:mr|mrs|miss|dr|prof|sir)'.  For example:

print "match3='$1' '$2'\n" if
($T=~/^((?:mr|mrs|miss|dr|prof|sir) .{5,}?)\n/smi);

would give output:

match3='Miss Jayne Doe' ''

On Wed, 2 Dec 2020, Gary Stainburn wrote:

> I have an array of regex expressions that I apply to text returned from
> tesseract.
> 
> Each match that I get then gets stored for future processing. However, I'm
> struggling with one regex.
> 
> The problem is that:
> 
> 1) with brackets round the titles it returns two matches.
> 2) without brackets, it returns nothing.
> 
> Can anyone point me at the correct syntax please.
> 
> Gary
> 
> [root@dev dev]# ./t
> match1='Miss Jayne Doe' 'Miss'
> [root@dev dev]# cat t
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $T=< Customer name and address
> Miss Jayne Doe
> 19 Their Street
> Somewehere
> In Yorkshire
> IN1 3YY
> EOF
> 
> print "match1='$1' '$2'\n" if ($T=~/^((mr|mrs|miss|dr|prof|sir)
> .{5,}?)\n/smi);
> print "match2='$1' '$2'\n" if ($T=~/^(mr|mrs|miss|dr|prof|sir .{5,}?)\n/smi);
> [root@dev dev]#
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




regex help - only one value returned

2020-12-02 Thread Gary Stainburn
I have an array of regex expressions that I apply to text returned from 
tesseract.


Each match that I get then gets stored for future processing. However, 
I'm struggling with one regex.


The problem is that:

1) with brackets round the titles it returns two matches.
2) without brackets, it returns nothing.

Can anyone point me at the correct syntax please.

Gary

[root@dev dev]# ./t
match1='Miss Jayne Doe' 'Miss'
[root@dev dev]# cat t
#!/usr/bin/perl

use strict;
use warnings;

my $T=<print "match1='$1' '$2'\n" if ($T=~/^((mr|mrs|miss|dr|prof|sir) 
.{5,}?)\n/smi);
print "match2='$1' '$2'\n" if ($T=~/^(mr|mrs|miss|dr|prof|sir 
.{5,}?)\n/smi);

[root@dev dev]#

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help me with a regex problem

2019-10-26 Thread Dermot
You might consider using Regexp::Common::net. It provides a convenient set
of functions for matching IP v4, v6 and mac addresses.


https://metacpan.org/pod/Regexp::Common::net

On Fri, 25 Oct 2019 at 19:43, John W. Krahn  wrote:

> On 2019-10-25 3:23 a.m., Maggie Q Roth wrote:
> >   Hello
>
> Hello.
>
> > There are two primary types of lines in the log:
>
> What are those two types?  How do you define them?
>
>
> > 60.191.38.xx/
> > 42.120.161.xx   /archives/1005
>
>  From my point of view those two lines have two fields, the first looks
> like an IP address and the second looks like a file path.  In other
> words I can't distinguish the difference between these two "types".
>
>
> > I know how to write regex to match each line, but don't get the good
> result
> > with one regex to match both lines.
> >
> > Can you help?
>
> Perhaps if you could describe the problem better?
>
>
> John
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Help me with a regex problem

2019-10-25 Thread John W. Krahn

On 2019-10-25 3:23 a.m., Maggie Q Roth wrote:

  Hello


Hello.


There are two primary types of lines in the log:


What are those two types?  How do you define them?



60.191.38.xx/
42.120.161.xx   /archives/1005


From my point of view those two lines have two fields, the first looks 
like an IP address and the second looks like a file path.  In other 
words I can't distinguish the difference between these two "types".




I know how to write regex to match each line, but don't get the good result
with one regex to match both lines.

Can you help?


Perhaps if you could describe the problem better?


John

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help me with a regex problem

2019-10-25 Thread Andy Bach
/(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/

To avoid the "leaning toothpick" problem, Perl lets use different match
delimiters, so the above is the same as:
m#(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?/.*)#

I assume you want to capture the IP and the path, right?
if ( $entry =~ m#([\d.]+)\s+(/\S+)# ) {
   my ($ip, $path) = ($1, $2);
   print "IP $ip asked for path $path\n";

On Fri, Oct 25, 2019 at 5:28 AM Илья Рассадин  wrote:

> For example, this regex
>
> /(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/
>
> On 25.10.2019 13:23, Maggie Q Roth wrote:
> > Hello
> >
> > There are two primary types of lines in the log:
> >
> > 60.191.38.xx/
> > 42.120.161.xx   /archives/1005
> >
> > I know how to write regex to match each line, but don't get the good
> > result with one regex to match both lines.
> >
> > Can you help?
> >
> > Thanks,
> > Maggie
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: Help me with a regex problem

2019-10-25 Thread Benjamin S Pendygraft II
That is a backslash followed by a forward slash. The backslash tells the
regex parser to treat the next character as a literal character. Useful for
matching periods, question marks, brackets, etc.
A period matches any character once and an asterisk matches the previous
character any number of times. .* basically means match everything.

Apologies if this is formatted incorrectly. Sending from my phone.

On Fri, Oct 25, 2019 at 06:37 Maggie Q Roth  wrote:

> what's V.*?
>
> Maggie
>
> On Fri, Oct 25, 2019 at 6:28 PM Илья Рассадин  wrote:
>
>> For example, this regex
>>
>> /(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/
>>
>> On 25.10.2019 13:23, Maggie Q Roth wrote:
>> > Hello
>> >
>> > There are two primary types of lines in the log:
>> >
>> > 60.191.38.xx/
>> > 42.120.161.xx   /archives/1005
>> >
>> > I know how to write regex to match each line, but don't get the good
>> > result with one regex to match both lines.
>> >
>> > Can you help?
>> >
>> > Thanks,
>> > Maggie
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>> --
Benjamin Pendygraft


Re: Help me with a regex problem

2019-10-25 Thread X Dungeness
my $n = '[0-9]{1,3}';
if  (  =~ (  m[ (?:$n\.){3} $n \s+ \S+ ]x )
{
   # match
}


On Fri, Oct 25, 2019 at 3:37 AM Maggie Q Roth  wrote:

> what's V.*?
>
> Maggie
>
> On Fri, Oct 25, 2019 at 6:28 PM Илья Рассадин  wrote:
>
>> For example, this regex
>>
>> /(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/
>>
>> On 25.10.2019 13:23, Maggie Q Roth wrote:
>> > Hello
>> >
>> > There are two primary types of lines in the log:
>> >
>> > 60.191.38.xx/
>> > 42.120.161.xx   /archives/1005
>> >
>> > I know how to write regex to match each line, but don't get the good
>> > result with one regex to match both lines.
>> >
>> > Can you help?
>> >
>> > Thanks,
>> > Maggie
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>


Re: Help me with a regex problem

2019-10-25 Thread Maggie Q Roth
what's V.*?

Maggie

On Fri, Oct 25, 2019 at 6:28 PM Илья Рассадин  wrote:

> For example, this regex
>
> /(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/
>
> On 25.10.2019 13:23, Maggie Q Roth wrote:
> > Hello
> >
> > There are two primary types of lines in the log:
> >
> > 60.191.38.xx/
> > 42.120.161.xx   /archives/1005
> >
> > I know how to write regex to match each line, but don't get the good
> > result with one regex to match both lines.
> >
> > Can you help?
> >
> > Thanks,
> > Maggie
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Help me with a regex problem

2019-10-25 Thread Илья Рассадин

For example, this regex

/(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/

On 25.10.2019 13:23, Maggie Q Roth wrote:

Hello

There are two primary types of lines in the log:

60.191.38.xx        /
42.120.161.xx       /archives/1005

I know how to write regex to match each line, but don't get the good 
result with one regex to match both lines.


Can you help?

Thanks,
Maggie


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Help me with a regex problem

2019-10-25 Thread Maggie Q Roth
 Hello

There are two primary types of lines in the log:

60.191.38.xx/
42.120.161.xx   /archives/1005

I know how to write regex to match each line, but don't get the good result
with one regex to match both lines.

Can you help?

Thanks,
Maggie


Re: Common regex for timedate

2018-11-19 Thread Asad
Thanks, I'll check them out.

On Wed, Nov 14, 2018 at 11:17 PM Andy Bach  wrote:

> > Yes the purpose is to compare the timestamps ans yes these are the only
> two formats .
>
> Then you probably want to look at modules, like Date::Manip, google has
> lots of suggestions:
>
> https://stackoverflow.com/questions/4199504/what-is-the-best-way-to-compare-dates-in-perl
> https://www.perlmonks.org/?node_id=1100934
> https://metacpan.org/pod/Class::Date
>
> The first advantage is they'll do the compare for you, the bigger one is
> they can parse those date strings automagically. YOu could look at the
> built-in POSIX::strftime (perldoc POSIX
>strftime
>Convert date and time information to string.  Returns the
> string.
>
>Synopsis:
>
>strftime(fmt, sec, min, hour, mday, mon, year, wday
> = -1, yday = -1, isdst = -1)
>
>The month ("mon"), weekday ("wday"), and yearday ("yday")
> begin at zero.  I.e. January is 0, not 1; Sunday is 0, not 1; January 1st
> is 0, not
>1.  The year ("year") is given in years since 1900.  I.e.,
> the year 1995 is 95; the year 2001 is 101.  Consult your system’s
> "strftime()"
>manpage for details about these and the other arguments.
>
>If you want your code to be portable, your format ("fmt")
> argument should use only the conversion specifiers defined by the ANSI C
> standard
>(C89, to play safe).  These are "aAbBcdHIjmMpSUwWxXyYZ%".
> But even then, the results of some of the conversion specifiers are
> non-portable.
>For example, the specifiers "aAbBcpZ" change according to
> the locale settings of the user, and both how to set locales (the locale
> names) and
>what output to expect are non-standard.  The specifier "c"
> changes according to the timezone settings of the user and the timezone
>computation rules of the operating system.  The "Z"
> specifier is notoriously unportable since the names of timezones are
> non-standard.
>Sticking to the numeric specifiers is the safest route.
>
>The given arguments are made consistent as though by
> calling "mktime()" before calling your system’s "strftime()" function,
> except that the
>"isdst" value is not affected.
>
>The string for Tuesday, December 12, 1995.
>
>$str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0,
> 12, 11, 95, 2 );
>print "$str\n";
>
> you'll have to use the REs to get the pieces (month, date etc) out
> yourself that way. Convert the dates to epoch seconds and compare.  You do,
> apparently, need to take into account timezones, as your date strings:
> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
> Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>
> one is -12 the other +2. With a little manipulation, those strings could
> be handled by the date utility
> $ date -d '05-JUL-18 10:19:42'
> Thu Jul  5 10:19:42 CDT 2018
>
> $ date -d '10/17/18 12:28:12'
> Wed Oct 17 12:28:12 CDT 2018
>
> so, for epoch seconds
> $ date -d '10/17/18 12:28:12' "+%s"
> 1539797292
> $ date -d '05-JUL-18 10:19:42 ' "+%s"
> 1530803982
>
> That's ignoring TZ
>
> On Tue, Nov 13, 2018 at 5:38 PM Asad  wrote:
>
>> Hi Andy ,
>>
>>  thanks for the reply . Yes the purpose is to compare the
>> timestamps ans yes these are the only two formats .
>>
>> Thanks,
>>
>> On Wed, Nov 14, 2018 at 2:48 AM Andy Bach  wrote:
>>
>>> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
>>> Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>>>
>>> > I created on regex
>>> : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9]
>>> > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>>>
>>> Right as your first string has word chars for the month, not digits. So,
>>> a straight forward, if only lightly useful one would get both, but as
>>> they've got entirely different orders, you're not going to be able to do
>>> much with the result. You'd be better off looking at 2 separate ones, esp.
>>> if you know one will be prefixed by "upgrade" and the other by "apply" or
>>> some similar list of words:
>>> if ( $str =~
>>> /upgrade.sql\s+on\s+(\d{2}-\w{3}-\d{2})\s+(012][0-9]:[0-5][0-9]:[0-5][0-9])/
>&g

Re: Common regex for timedate

2018-11-14 Thread Andy Bach
> Yes the purpose is to compare the timestamps ans yes these are the only
two formats .

Then you probably want to look at modules, like Date::Manip, google has
lots of suggestions:
https://stackoverflow.com/questions/4199504/what-is-the-best-way-to-compare-dates-in-perl
https://www.perlmonks.org/?node_id=1100934
https://metacpan.org/pod/Class::Date

The first advantage is they'll do the compare for you, the bigger one is
they can parse those date strings automagically. YOu could look at the
built-in POSIX::strftime (perldoc POSIX
   strftime
   Convert date and time information to string.  Returns the
string.

   Synopsis:

   strftime(fmt, sec, min, hour, mday, mon, year, wday
= -1, yday = -1, isdst = -1)

   The month ("mon"), weekday ("wday"), and yearday ("yday")
begin at zero.  I.e. January is 0, not 1; Sunday is 0, not 1; January 1st
is 0, not
   1.  The year ("year") is given in years since 1900.  I.e.,
the year 1995 is 95; the year 2001 is 101.  Consult your system’s
"strftime()"
   manpage for details about these and the other arguments.

   If you want your code to be portable, your format ("fmt")
argument should use only the conversion specifiers defined by the ANSI C
standard
   (C89, to play safe).  These are "aAbBcdHIjmMpSUwWxXyYZ%".
But even then, the results of some of the conversion specifiers are
non-portable.
   For example, the specifiers "aAbBcpZ" change according to
the locale settings of the user, and both how to set locales (the locale
names) and
   what output to expect are non-standard.  The specifier "c"
changes according to the timezone settings of the user and the timezone
   computation rules of the operating system.  The "Z"
specifier is notoriously unportable since the names of timezones are
non-standard.
   Sticking to the numeric specifiers is the safest route.

   The given arguments are made consistent as though by calling
"mktime()" before calling your system’s "strftime()" function, except that
the
   "isdst" value is not affected.

   The string for Tuesday, December 12, 1995.

   $str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0,
12, 11, 95, 2 );
   print "$str\n";

you'll have to use the REs to get the pieces (month, date etc) out yourself
that way. Convert the dates to epoch seconds and compare.  You do,
apparently, need to take into account timezones, as your date strings:
Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
Calling apply.sql on 17.10.18 12:28:12,447849 +02:

one is -12 the other +2. With a little manipulation, those strings could be
handled by the date utility
$ date -d '05-JUL-18 10:19:42'
Thu Jul  5 10:19:42 CDT 2018

$ date -d '10/17/18 12:28:12'
Wed Oct 17 12:28:12 CDT 2018

so, for epoch seconds
$ date -d '10/17/18 12:28:12' "+%s"
1539797292
$ date -d '05-JUL-18 10:19:42 ' "+%s"
1530803982

That's ignoring TZ

On Tue, Nov 13, 2018 at 5:38 PM Asad  wrote:

> Hi Andy ,
>
>  thanks for the reply . Yes the purpose is to compare the
> timestamps ans yes these are the only two formats .
>
> Thanks,
>
> On Wed, Nov 14, 2018 at 2:48 AM Andy Bach  wrote:
>
>> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
>> Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>>
>> > I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9]
>> > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>>
>> Right as your first string has word chars for the month, not digits. So,
>> a straight forward, if only lightly useful one would get both, but as
>> they've got entirely different orders, you're not going to be able to do
>> much with the result. You'd be better off looking at 2 separate ones, esp.
>> if you know one will be prefixed by "upgrade" and the other by "apply" or
>> some similar list of words:
>> if ( $str =~
>> /upgrade.sql\s+on\s+(\d{2}-\w{3}-\d{2})\s+(012][0-9]:[0-5][0-9]:[0-5][0-9])/
>> # got $1 eq "date-mon-year" and $2 eq "hr-min-sec"
>>  or $str =~
>> /apply.sql\s+on\s+(\d{2}\.\d{2}\.\d{2})\s+([012][0-9]:[0-5][0-9]:[0-5][0-9])/
>> # got $1 eq "date.month.year" and $2 eq "hr-min-sec"
>> ) {
>> # date str's matched
>>
>> > I need a common regex which matches both the lines ?
>> You might want to let us know why? What you're going to do w/ the match.
>> Are you validating the strings and, if so, will you reject non-matches?
>> Are you looking 

Re: Common regex for timedate

2018-11-13 Thread Asad
Hi Andy ,

 thanks for the reply . Yes the purpose is to compare the
timestamps ans yes these are the only two formats .

Thanks,

On Wed, Nov 14, 2018 at 2:48 AM Andy Bach  wrote:

> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
> Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>
> > I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9]
> > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>
> Right as your first string has word chars for the month, not digits. So, a
> straight forward, if only lightly useful one would get both, but as they've
> got entirely different orders, you're not going to be able to do much with
> the result. You'd be better off looking at 2 separate ones, esp. if you
> know one will be prefixed by "upgrade" and the other by "apply" or some
> similar list of words:
> if ( $str =~
> /upgrade.sql\s+on\s+(\d{2}-\w{3}-\d{2})\s+(012][0-9]:[0-5][0-9]:[0-5][0-9])/
> # got $1 eq "date-mon-year" and $2 eq "hr-min-sec"
>  or $str =~
> /apply.sql\s+on\s+(\d{2}\.\d{2}\.\d{2})\s+([012][0-9]:[0-5][0-9]:[0-5][0-9])/
> # got $1 eq "date.month.year" and $2 eq "hr-min-sec"
> ) {
> # date str's matched
>
> > I need a common regex which matches both the lines ?
> You might want to let us know why? What you're going to do w/ the match.
> Are you validating the strings and, if so, will you reject non-matches?
> Are you looking to break them up into parts, $date, $mon, $year ... ?
> Compare them, maybe to find the difference?  Are these the only 2 formats
> you'll be looking at, that is, maybe some might be 17.10.2018, or 17-10-18?
>
>
>
> On Mon, Nov 12, 2018 at 6:49 AM Asad  wrote:
>
>> Hi all ,
>>
>>I have two stings from logfile how can we have a common regex
>> so that its parse datetime details for further parsing ;
>>
>> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
>> Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>>
>> I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]
>> this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>>
>> I need a common regex which matches both the lines ?
>>
>>
>> Thanks,
>> --
>> Asad Hasan
>> +91 9582111698
>>
>
>
> --
>
> a
>
> Andy Bach,
> afb...@gmail.com
> 608 658-1890 cell
> 608 261-5738 wk
>


-- 
Asad Hasan
+91 9582111698


Re: Common regex for timedate

2018-11-13 Thread Andy Bach
Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
Calling apply.sql on 17.10.18 12:28:12,447849 +02:

> I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9]
> this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:

Right as your first string has word chars for the month, not digits. So, a
straight forward, if only lightly useful one would get both, but as they've
got entirely different orders, you're not going to be able to do much with
the result. You'd be better off looking at 2 separate ones, esp. if you
know one will be prefixed by "upgrade" and the other by "apply" or some
similar list of words:
if ( $str =~
/upgrade.sql\s+on\s+(\d{2}-\w{3}-\d{2})\s+(012][0-9]:[0-5][0-9]:[0-5][0-9])/
# got $1 eq "date-mon-year" and $2 eq "hr-min-sec"
 or $str =~
/apply.sql\s+on\s+(\d{2}\.\d{2}\.\d{2})\s+([012][0-9]:[0-5][0-9]:[0-5][0-9])/
# got $1 eq "date.month.year" and $2 eq "hr-min-sec"
) {
# date str's matched

> I need a common regex which matches both the lines ?
You might want to let us know why? What you're going to do w/ the match.
Are you validating the strings and, if so, will you reject non-matches?
Are you looking to break them up into parts, $date, $mon, $year ... ?
Compare them, maybe to find the difference?  Are these the only 2 formats
you'll be looking at, that is, maybe some might be 17.10.2018, or 17-10-18?



On Mon, Nov 12, 2018 at 6:49 AM Asad  wrote:

> Hi all ,
>
>I have two stings from logfile how can we have a common regex
> so that its parse datetime details for further parsing ;
>
> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
> Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>
> I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]
> this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>
> I need a common regex which matches both the lines ?
>
>
> Thanks,
> --
> Asad Hasan
> +91 9582111698
>


-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: Common regex for timedate

2018-11-13 Thread Дмитрий Ананьевский
On Mon, 12 Nov 2018 18:18:12 +0530
Asad  wrote:

> Hi all ,
> 
>I have two stings from logfile how can we have a common regex so
> that its parse datetime details for further parsing ;
> 
> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
> Calling apply.sql on 17.10.18 12:28:12,447849 +02:
> 
> I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]
> this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:
> 
> I need a common regex which matches both the lines ?
> 
> 
> Thanks,
> -- 
> Asad Hasan
> +91 9582111698

Hi Asad!

Try \d\S+\s[\d.:]{8}

-- 
Дмитрий Ананьевский 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Common regex for timedate

2018-11-12 Thread David Y Wagner via beginners
You could change the first portion of RegEx to

\d{2}[.\-](\d{2}|\D{3})[.\-]

This could cover all the valid Month codes, but this will look for the hyphen 
or period and two digit month or three non digits and then the the hyphen or 
period following. There is much more you could do, but this covers the initial 
start.

Did not test, but believe it should find both items...

Wags ;)
WagsWorld
Hebrews 4:15
Ph(primary) : 408-914-1341
Ph(secondary): 408-761-7391
On Nov 12, 2018, 09:37 -0800, Asad , wrote:
> Hi all ,
>
>            I have two stings from logfile how can we have a common regex so 
> that its parse datetime details for further parsing ;
>
> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
> Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>
> I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]
> this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:
>
> I need a common regex which matches both the lines ?
>
>
> Thanks,
> --
> Asad Hasan
> +91 9582111698


Common regex for timedate

2018-11-12 Thread Asad
Hi all ,

   I have two stings from logfile how can we have a common regex so
that its parse datetime details for further parsing ;

Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12
Calling apply.sql on 17.10.18 12:28:12,447849 +02:

I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]
this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02:

I need a common regex which matches both the lines ?


Thanks,
-- 
Asad Hasan
+91 9582111698


Re: How to compare timestamp in two different files(regex)

2018-10-25 Thread armando perez pena
Dear All,

This is a Perl place for Python there are many places.

BR,

Armando

El 25/10/18 a las 17:17, Chris Fedde escribió:
why post a python solution here?

On Thu, Oct 25, 2018 at 8:58 AM Asad 
mailto:asad.hasan2...@gmail.com>> wrote:
Hi ,

Yes i have the code :


import re
import datetime
from datetime import timedelta

Header = "*"

f3 = open ( r"D:\QI\logA.txt", 'r' )
string = f3.read ()
regex = re.compile ( "\n" )
st = regex.sub ( " ", string )
st1 = st.split ( " " )

if re.search ('ERR-1:', st ):
x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)", st )
j = x[0][0] + " "+ x[0][1]+" " + x[0][2] +":"+ x[0][3]+":" + x[0][4]+" " + 
x[0][5]
h = x[1][0] + " "+ x[1][1]+" "+ x[1][2] +":" + x[1][3] +":"+ x[1][4] +" "+ 
x[1][5]
y = datetime.datetime.strptime ( j, '%b %d %H:%M:%S %Y' )
print y
k = datetime.datetime.strptime ( h, '%b %d %H:%M:%S %Y' )
print k

f4 = open ( r"D:\QI\logC11.txt", 'r' )

string1 = f4.read ()
reg = re.compile ( "\n" )
newst = reg.sub ( " ", string1 )
newst1 = newst.split ( " " )

if re.search ( "ERR-2", newst ):
a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", newst )
for i in range ( len ( a ) ):
newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
if newtime > y and newtime < k:
   print "Install patch1"

if re.search ( "ERR-3", newst ):
a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", newst )
for i in range ( len ( a ) ):
newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
if newtime > y and newtime < k:
print newtime, y, k
print "Install patch2"

==

output i get :

Install patch1   - wrong solution
2018-10-22 10:21:23 2018-10-22 10:21:15 2018-10-22 10:21:25
Install patch2   - correct solution










On Thu, Oct 25, 2018 at 6:56 PM Jim Gibson 
mailto:jimsgib...@gmail.com>> wrote:
(Please reply to the list.)

If you have written code that extracts the date and time from the ‘LOG flle 
opened’ lines in the log file, then please show us your code. You seem to be 
asking other people to write your program for you. You will get better help if 
you appear to be making an effort to solve these problems yourself.

Anyone wishing to get help from a forum such as 
beginners@perl.org<mailto:beginners@perl.org> would do well to read this 
website on how to ask smart questions:

<http://www.catb.org/~esr/faqs/smart-questions.html<http://www.catb.org/%7Eesr/faqs/smart-questions.html>>

Now, to address your problem:

If you have a starting time and an ending time for a window within which you 
wish to print lines from a log file, you can use a flag variable to indicate 
when the lines you are reading are within that window. The pseudo-logic would 
be something like this:

1.initialize print flag to false
2. Save starting and ending times in variables
3. loop to read or process sequential lines in the file
  a. See if line contains time
  b. If it does, extract time
  c. Compare time in line to starting time
  d. If line time is greater than or equal to start time, set print flag to true
  e. If line time is greater than ending time, set print flag to false
  f. If print flag is true print line
  g. End of loop — process next line

If you need help with any of these steps, please show us your code, what your 
code is doing, and what you expect your code to do that it is not doing.

Thanks.

> On Oct 24, 2018, at 10:50 PM, Asad 
> mailto:asad.hasan2...@gmail.com>> wrote:
>
> Hi Jim/All,
>
>  I have already done that now the issue is how do I  print  the 
> lines from file2 only between start $t2 and <$t3  then process these lines is 
> next step ?
>  Please share the code if you have .
>
> Thanks,
>
>
> On Thu, Oct 25, 2018 at 11:04 AM Jim Gibson 
> mailto:jimsgib...@gmail.com>> wrote:
>
>
> > On Oct 24, 2018, at 9:54 PM, Asad 
> > mailto:asad.hasan2...@gmail.com>> wrote:
> >
> > Thank all now I am able to progress :
> >
> > file1  i am able to extract the start and end timestamp
> > file 2  i am able to extract the timestamp
> >
> > used the following
> > my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S 
> > %Y'); coming from file1
> >
> > my $t2 = Time::Piece->strptime('02/23

Re: How to compare timestamp in two different files(regex)

2018-10-25 Thread Chris Fedde
why post a python solution here?

On Thu, Oct 25, 2018 at 8:58 AM Asad  wrote:

> Hi ,
>
> Yes i have the code :
>
> import re
> import datetime
> from datetime import timedelta
>
> Header = "*"
>
> f3 = open ( r"D:\QI\logA.txt", 'r' )
> string = f3.read ()
> regex = re.compile ( "\n" )
> st = regex.sub ( " ", string )
> st1 = st.split ( " " )
>
> if re.search ('ERR-1:', st ):
> x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)", st )
> j = x[0][0] + " "+ x[0][1]+" " + x[0][2] +":"+ x[0][3]+":" + x[0][4]+" " 
> + x[0][5]
> h = x[1][0] + " "+ x[1][1]+" "+ x[1][2] +":" + x[1][3] +":"+ x[1][4] +" 
> "+ x[1][5]
> y = datetime.datetime.strptime ( j, '%b %d %H:%M:%S %Y' )
> print y
> k = datetime.datetime.strptime ( h, '%b %d %H:%M:%S %Y' )
> print k
>
> f4 = open ( r"D:\QI\logC11.txt", 'r' )
>
> string1 = f4.read ()
> reg = re.compile ( "\n" )
> newst = reg.sub ( " ", string1 )
> newst1 = newst.split ( " " )
>
> if re.search ( "ERR-2", newst ):
> a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", 
> newst )
> for i in range ( len ( a ) ):
> newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
> if newtime > y and newtime < k:
>print "Install patch1"
>
> if re.search ( "ERR-3", newst ):
> a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", 
> newst )
> for i in range ( len ( a ) ):
> newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
> if newtime > y and newtime < k:
> print newtime, y, k
> print "Install patch2"
>
> ==
>
> output i get :
>
> *Install patch1   - wrong solution
> 2018-10-22 10:21:23 2018-10-22 10:21:15 2018-10-22 10:21:25
> Install patch2   - correct solution *
>
>
>
>
>
> On Thu, Oct 25, 2018 at 6:56 PM Jim Gibson  wrote:
>
>> (Please reply to the list.)
>>
>> If you have written code that extracts the date and time from the ‘LOG
>> flle opened’ lines in the log file, then please show us your code. You seem
>> to be asking other people to write your program for you. You will get
>> better help if you appear to be making an effort to solve these problems
>> yourself.
>>
>> Anyone wishing to get help from a forum such as beginners@perl.org would
>> do well to read this website on how to ask smart questions:
>>
>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>
>> Now, to address your problem:
>>
>> If you have a starting time and an ending time for a window within which
>> you wish to print lines from a log file, you can use a flag variable to
>> indicate when the lines you are reading are within that window. The
>> pseudo-logic would be something like this:
>>
>> 1.initialize print flag to false
>> 2. Save starting and ending times in variables
>> 3. loop to read or process sequential lines in the file
>>   a. See if line contains time
>>   b. If it does, extract time
>>   c. Compare time in line to starting time
>>   d. If line time is greater than or equal to start time, set print flag
>> to true
>>   e. If line time is greater than ending time, set print flag to false
>>   f. If print flag is true print line
>>   g. End of loop — process next line
>>
>> If you need help with any of these steps, please show us your code, what
>> your code is doing, and what you expect your code to do that it is not
>> doing.
>>
>> Thanks.
>>
>> > On Oct 24, 2018, at 10:50 PM, Asad  wrote:
>> >
>> > Hi Jim/All,
>> >
>> >  I have already done that now the issue is how do I  print
>> the lines from file2 only between start $t2 and <$t3  then process these
>> lines is next step ?
>> >  Please share the code if you have .
>> >
>> > Thanks,
>> >
>> >
>> > On Thu, Oct 25, 2018 at 11:04 AM Jim Gibson 
>> wrote:
>> >
>> >
>> > > On Oct 24, 2018, at 9:54 PM, Asad  wrote:
>> > >
>> > > Thank all now I am able to progress :
>> > >
>> > > file1  i am able to extract the start an

Re: How to compare timestamp in two different files(regex)

2018-10-25 Thread Asad
Hi ,

Yes i have the code :

import re
import datetime
from datetime import timedelta

Header = "*"

f3 = open ( r"D:\QI\logA.txt", 'r' )
string = f3.read ()
regex = re.compile ( "\n" )
st = regex.sub ( " ", string )
st1 = st.split ( " " )

if re.search ('ERR-1:', st ):
x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)", st )
j = x[0][0] + " "+ x[0][1]+" " + x[0][2] +":"+ x[0][3]+":" +
x[0][4]+" " + x[0][5]
h = x[1][0] + " "+ x[1][1]+" "+ x[1][2] +":" + x[1][3] +":"+
x[1][4] +" "+ x[1][5]
y = datetime.datetime.strptime ( j, '%b %d %H:%M:%S %Y' )
print y
k = datetime.datetime.strptime ( h, '%b %d %H:%M:%S %Y' )
print k

f4 = open ( r"D:\QI\logC11.txt", 'r' )

string1 = f4.read ()
reg = re.compile ( "\n" )
newst = reg.sub ( " ", string1 )
newst1 = newst.split ( " " )

if re.search ( "ERR-2", newst ):
a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", newst )
for i in range ( len ( a ) ):
newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
if newtime > y and newtime < k:
   print "Install patch1"

if re.search ( "ERR-3", newst ):
a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", newst )
for i in range ( len ( a ) ):
newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
if newtime > y and newtime < k:
print newtime, y, k
print "Install patch2"

==

output i get :

*Install patch1   - wrong solution
2018-10-22 10:21:23 2018-10-22 10:21:15 2018-10-22 10:21:25
Install patch2   - correct solution *





On Thu, Oct 25, 2018 at 6:56 PM Jim Gibson  wrote:

> (Please reply to the list.)
>
> If you have written code that extracts the date and time from the ‘LOG
> flle opened’ lines in the log file, then please show us your code. You seem
> to be asking other people to write your program for you. You will get
> better help if you appear to be making an effort to solve these problems
> yourself.
>
> Anyone wishing to get help from a forum such as beginners@perl.org would
> do well to read this website on how to ask smart questions:
>
> <http://www.catb.org/~esr/faqs/smart-questions.html>
>
> Now, to address your problem:
>
> If you have a starting time and an ending time for a window within which
> you wish to print lines from a log file, you can use a flag variable to
> indicate when the lines you are reading are within that window. The
> pseudo-logic would be something like this:
>
> 1.initialize print flag to false
> 2. Save starting and ending times in variables
> 3. loop to read or process sequential lines in the file
>   a. See if line contains time
>   b. If it does, extract time
>   c. Compare time in line to starting time
>   d. If line time is greater than or equal to start time, set print flag
> to true
>   e. If line time is greater than ending time, set print flag to false
>   f. If print flag is true print line
>   g. End of loop — process next line
>
> If you need help with any of these steps, please show us your code, what
> your code is doing, and what you expect your code to do that it is not
> doing.
>
> Thanks.
>
> > On Oct 24, 2018, at 10:50 PM, Asad  wrote:
> >
> > Hi Jim/All,
> >
> >  I have already done that now the issue is how do I  print
> the lines from file2 only between start $t2 and <$t3  then process these
> lines is next step ?
> >  Please share the code if you have .
> >
> > Thanks,
> >
> >
> > On Thu, Oct 25, 2018 at 11:04 AM Jim Gibson 
> wrote:
> >
> >
> > > On Oct 24, 2018, at 9:54 PM, Asad  wrote:
> > >
> > > Thank all now I am able to progress :
> > >
> > > file1  i am able to extract the start and end timestamp
> > > file 2  i am able to extract the timestamp
> > >
> > > used the following
> > > my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S
> %Y'); coming from file1
> > >
> > > my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y
> %H:%M:%S');   coming from file2
> > >
> > > my $t3 = Time::Piece->strptime('Feb 23 01:10:36 2018', '%b %d %H:%M:%S
> %Y');  coming from file 1
> > >
> > > if ($t2 > $t1 and $t2 < $t3) { ... }   till here it working fine
> &g

Re: How to compare timestamp in two different files(regex)

2018-10-25 Thread Jim Gibson
(Please reply to the list.)

If you have written code that extracts the date and time from the ‘LOG flle 
opened’ lines in the log file, then please show us your code. You seem to be 
asking other people to write your program for you. You will get better help if 
you appear to be making an effort to solve these problems yourself.

Anyone wishing to get help from a forum such as beginners@perl.org would do 
well to read this website on how to ask smart questions:



Now, to address your problem:

If you have a starting time and an ending time for a window within which you 
wish to print lines from a log file, you can use a flag variable to indicate 
when the lines you are reading are within that window. The pseudo-logic would 
be something like this:

1.initialize print flag to false
2. Save starting and ending times in variables
3. loop to read or process sequential lines in the file
  a. See if line contains time
  b. If it does, extract time
  c. Compare time in line to starting time
  d. If line time is greater than or equal to start time, set print flag to true
  e. If line time is greater than ending time, set print flag to false
  f. If print flag is true print line
  g. End of loop — process next line

If you need help with any of these steps, please show us your code, what your 
code is doing, and what you expect your code to do that it is not doing.

Thanks.
 
> On Oct 24, 2018, at 10:50 PM, Asad  wrote:
> 
> Hi Jim/All,
> 
>  I have already done that now the issue is how do I  print  the 
> lines from file2 only between start $t2 and <$t3  then process these lines is 
> next step ?
>  Please share the code if you have .
> 
> Thanks,
> 
> 
> On Thu, Oct 25, 2018 at 11:04 AM Jim Gibson  wrote:
> 
> 
> > On Oct 24, 2018, at 9:54 PM, Asad  wrote:
> > 
> > Thank all now I am able to progress :
> > 
> > file1  i am able to extract the start and end timestamp 
> > file 2  i am able to extract the timestamp 
> > 
> > used the following 
> > my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S 
> > %Y'); coming from file1
> > 
> > my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S');   
> > coming from file2
> > 
> > my $t3 = Time::Piece->strptime('Feb 23 01:10:36 2018', '%b %d %H:%M:%S 
> > %Y');  coming from file 1
> > 
> > if ($t2 > $t1 and $t2 < $t3) { ... }   till here it working fine
> > 
> >  now I would like to print all lines from file2 starting from  t2 02/23/18 
> > 01:10:33 till very next timestamp which will be  greater than t3 :
> > 
> > 
> > 
> > for example the file2  would look like this:
> > 
> > ===
> > 
> >  LOG file opened at 02/23/18 01:10:33
> > 
> > ERR-05007:   Warning: Intra source concurrency disabled because the 
> > preprocessor option is being used.
> > 
> > Field Definitions for table OPATCH_XML_INV
> > 
> > eject rows with all null fields
> > 
> >   Fields in Data Source: 
> > 
> > 
> > 
> > ERR-04095:failed: Unable to create patchObject
> > 
> > Possible causes are:
> > 
> >  "
> > 
> >  LOG file opened at 04/26/18 06:10:33
> > 
> > ===
> >   
> > 
> > This logfile may have other time but i would to extract only the above 
> > lines because messages occured between t1 and t3 after I extract these i 
> > want to print the error lines for example ERR-05007
> > 
> > the issue I am facing if there are multiple error in the file it is 
> > printing for each occurance of  ERR-05007 instead it should print only the 
> > error lines between t1 and t3 from file2
> > 
> > Please advice ,
> > 
> > thanks,
> 
> For each line is the file, use a regular expression to look for lines 
> starting with ‘LOG file opened at’ and extract the time that follows in that 
> line. Then, use Time::Piece to create an object of that class using the 
> date/time extracted. Then, you can compare the time in that line to your 
> start and stop times in $t2 and $t3 (or is it $t1 and $t3?).
> 
> 
> Jim Gibson
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
> 
> 
> -- 
> Asad Hasan
> +91 9582111698

Jim Gibson

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Jim Gibson



> On Oct 24, 2018, at 9:54 PM, Asad  wrote:
> 
> Thank all now I am able to progress :
> 
> file1  i am able to extract the start and end timestamp 
> file 2  i am able to extract the timestamp 
> 
> used the following 
> my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S %Y'); 
> coming from file1
> 
> my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S'); 
>   coming from file2
> 
> my $t3 = Time::Piece->strptime('Feb 23 01:10:36 2018', '%b %d %H:%M:%S %Y');  
> coming from file 1
> 
> if ($t2 > $t1 and $t2 < $t3) { ... }   till here it working fine
> 
>  now I would like to print all lines from file2 starting from  t2 02/23/18 
> 01:10:33 till very next timestamp which will be  greater than t3 :
> 
> 
> 
> for example the file2  would look like this:
> 
> ===
> 
>  LOG file opened at 02/23/18 01:10:33
> 
> ERR-05007:   Warning: Intra source concurrency disabled because the 
> preprocessor option is being used.
> 
> Field Definitions for table OPATCH_XML_INV
> 
> eject rows with all null fields
> 
>   Fields in Data Source: 
> 
> 
> 
> ERR-04095:failed: Unable to create patchObject
> 
> Possible causes are:
> 
>  "
> 
>  LOG file opened at 04/26/18 06:10:33
> 
> ===
>   
> 
> This logfile may have other time but i would to extract only the above lines 
> because messages occured between t1 and t3 after I extract these i want to 
> print the error lines for example ERR-05007
> 
> the issue I am facing if there are multiple error in the file it is printing 
> for each occurance of  ERR-05007 instead it should print only the error lines 
> between t1 and t3 from file2
> 
> Please advice ,
> 
> thanks,

For each line is the file, use a regular expression to look for lines starting 
with ‘LOG file opened at’ and extract the time that follows in that line. Then, 
use Time::Piece to create an object of that class using the date/time 
extracted. Then, you can compare the time in that line to your start and stop 
times in $t2 and $t3 (or is it $t1 and $t3?).


Jim Gibson

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Asad
Thank all now I am able to progress :

file1  i am able to extract the start and end timestamp
file 2  i am able to extract the timestamp

used the following

my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S
%Y'); coming from file1

my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S');
 coming from file2

my $t3 = Time::Piece->strptime('Feb 23 01:10:36 2018', '%b %d %H:%M:%S
%Y');  coming from file 1

if ($t2 > $t1 and $t2 < $t3) { ... }   till here it working fine

 now I would like to print all lines from file2 starting from  t2 02/23/18
01:10:33 till very next timestamp which will be  greater than t3 :


for example the file2  would look like this:

===

 LOG file opened at 02/23/18 01:10:33

ERR-05007:   Warning: Intra source concurrency disabled because the
preprocessor option is being used.

Field Definitions for table OPATCH_XML_INV

eject rows with all null fields

  Fields in Data Source:


ERR-04095:failed: Unable to create patchObject

Possible causes are:

 "

 LOG file opened at 04/26/18 06:10:33

===
This logfile may have other time but i would to extract only the above
lines because messages occured between t1 and t3 after I extract these i
want to print the error lines for example ERR-05007

the issue I am facing if there are multiple error in the file it is
printing for each occurance of  ERR-05007 instead it should print only the
error lines between t1 and t3 from file2

Please advice ,

thanks,

On Thu, Oct 25, 2018 at 6:44 AM Martin McCormick 
wrote:

> Someone brought to my attention that I had failed to define a
> couple of variables in the sample code I posted and they were
> quite right.  I don't mind sharing my work but the entire
> application I wrote to get a brief local weather summary is
> 242 lines and I was trying to stay close to the topic, here, so I
> had shortened it and shortened it a bit too much.  Here is sample
> code that will actually run.  If you want to experiment with it,
> it should work fron anywhere in the world but practically, I
> doubt it works outside the united states though people in other
> countries can look up weather in US cities if you first get on the
> noaa.gov web site
>
>   http://noaa.gov
>
> and enter the city name you are interested in.  If you have a US
> postal zip code, that will work.  What you want is an xml file
> containing the local weather conditions for that location.  You
> will also get latitude and longitude which can help you get
> sunrise and sunset data from another web site that needs those
> data to give you the right table.
>
> In other words, you must set $wxfile to the name of the file for
> your city of interest.
>
> This code downloads the file for Stillwater, Oklahoma and
> the information in the xml file says that the recommend pickup
> time is 15 minutes past the hour so it modifies the time stamp to
> show 15 minutes past your current hour.  When you look at the
> code, you will see that it compares the current number of
> localtime seconds to the mtime value of the present file.  It
> will not get it again until 3600 seconds or 1 hour has passed
> since 15 minutes past the hour in which you downloaded it.
>
> Here is working code.  I did run it through perltidy but no
> telling what the mailing process will do so you will need to
> probably run perltidy again after you save the code.
>
> I am sorry for any confusion I caused.
>
> Cut here.
>
> #!/usr/bin/perl -w
> use strict;
> use warnings::unused;
> use Data::Dumper;
> use XML::Simple;
> use File::Basename;
> use Cwd;
> use File::stat;
> use Time::Local;
> my $homedir = "/tmp";
> my @t   = localtime(time);
> my $utcsec  = timelocal(@t);
> my $wxfile  = 'display.php?stid=KSWO';
>
> #I want that file to end up in a specific directory so:
> my $wxpath= $homedir . "/" . $wxfile;
> my $day   = 86400;   #seconds
> my $hour  = 3600;
> my $gmt_offset_in_seconds = timegm(@t) - timelocal(@t);
> my $tzoffset  = $gmt_offset_in_seconds / 3600;
>
> #many thanks to whoever wrote the quick way to determine TZ
> #offset from utc
>
> my $wxlast_update_time;
>
> #Grab conditions from NOAA if the file is stale or missing.
> if ( !stat($wxpath) ) {#The file is not there.
> system(
> "curl -s -o $wxpath 'http://w1.weather.gov/xml/current_obs/$wxfile
> '");
>
> #Change the mtime to a quarter past last hour.
> my $when = timelocal( 0, 15, $t[2], $t[3], $t[4], ( $t[5] - 100 ) );
> utime $when, $when, "$wxpath";
> } #The file is not there.
> else {#what normally happens
> my $wxstatRef = stat($wxpath);
> $wxlast_update_time = $wxstatRef->mtime();
> my $wxage = ( $utcsec - 

Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Martin McCormick
Someone brought to my attention that I had failed to define a
couple of variables in the sample code I posted and they were
quite right.  I don't mind sharing my work but the entire
application I wrote to get a brief local weather summary is
242 lines and I was trying to stay close to the topic, here, so I
had shortened it and shortened it a bit too much.  Here is sample
code that will actually run.  If you want to experiment with it,
it should work fron anywhere in the world but practically, I
doubt it works outside the united states though people in other
countries can look up weather in US cities if you first get on the
noaa.gov web site

  http://noaa.gov

and enter the city name you are interested in.  If you have a US
postal zip code, that will work.  What you want is an xml file
containing the local weather conditions for that location.  You
will also get latitude and longitude which can help you get
sunrise and sunset data from another web site that needs those
data to give you the right table.

In other words, you must set $wxfile to the name of the file for
your city of interest.

This code downloads the file for Stillwater, Oklahoma and
the information in the xml file says that the recommend pickup
time is 15 minutes past the hour so it modifies the time stamp to
show 15 minutes past your current hour.  When you look at the
code, you will see that it compares the current number of
localtime seconds to the mtime value of the present file.  It
will not get it again until 3600 seconds or 1 hour has passed
since 15 minutes past the hour in which you downloaded it.

Here is working code.  I did run it through perltidy but no
telling what the mailing process will do so you will need to
probably run perltidy again after you save the code.

I am sorry for any confusion I caused.

Cut here.

#!/usr/bin/perl -w
use strict;
use warnings::unused;
use Data::Dumper;
use XML::Simple;
use File::Basename;
use Cwd;
use File::stat;
use Time::Local;
my $homedir = "/tmp";
my @t   = localtime(time);
my $utcsec  = timelocal(@t);
my $wxfile  = 'display.php?stid=KSWO';

#I want that file to end up in a specific directory so:
my $wxpath= $homedir . "/" . $wxfile;
my $day   = 86400;   #seconds
my $hour  = 3600;
my $gmt_offset_in_seconds = timegm(@t) - timelocal(@t);
my $tzoffset  = $gmt_offset_in_seconds / 3600;

#many thanks to whoever wrote the quick way to determine TZ
#offset from utc

my $wxlast_update_time;

#Grab conditions from NOAA if the file is stale or missing.
if ( !stat($wxpath) ) {#The file is not there.
system(
"curl -s -o $wxpath 'http://w1.weather.gov/xml/current_obs/$wxfile'");

#Change the mtime to a quarter past last hour.
my $when = timelocal( 0, 15, $t[2], $t[3], $t[4], ( $t[5] - 100 ) );
utime $when, $when, "$wxpath";
} #The file is not there.
else {#what normally happens
my $wxstatRef = stat($wxpath);
$wxlast_update_time = $wxstatRef->mtime();
my $wxage = ( $utcsec - $wxlast_update_time );
if ( $wxage >= $hour ) {#File needs to be refreshed.

#The file should not be more than 3600 seconds old.
system(
"curl -s -o $wxpath 'http://w1.weather.gov/xml/current_obs/$wxfile'"
);

#Change the mtime to a quarter past.
my $when = timelocal( 0, 15, $t[2], $t[3], $t[4], ( $t[5] - 100 ) );
utime $when, $when, "$wxpath";
}#File needs to be refreshed.
}#what normally happens

# create object
my $xml = new XML::Simple;

# read XML file
my $data = $xml->XMLin("$wxpath");

print Dumper($data);

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Andy Bach
===> I  am using the following regex :

([A-Z][a-z]{2}\s)([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4})

> Both are working as expected I would like to know if these are good regex
or it can be better , please suggest .

Concurring with the others, your setting yourself up for trouble with the
RE route (famous saying: "So you have a programming problem and say, 'I
know, I solve it with a regex!' Now you have two problems"). As I
mentioned, Perl gives you epoch time and localtime() or POSIX::strftime let
you turn that into nice human-readable strings.

But to your RE, well, besides assuming there'll always be just one space,
you're capturing the spaces (and separators), which means you'll probably
need to ditch them later.  Looking a little closer, I don't think you're
using the capture parens for capturing. You're RE is actually sort of
validating the timestamp, so it'll fail on a different one, say with all
lower case month or no prefix zero or something. For handling data from
outside sources, it usually better to do a broader match and then test the
parts for validity so you will know which part failed.

if ( $file_info_str =~ /(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)/ )
{
  my ($mon, $date, $hour, $min, $sec, $year) = ($1, $2, $3, $4, $5, $6);'
... [ work with time stamp ]
}
else {
warn("unable to find time stamp: $file_info_string\n");
...

On Wed, Oct 24, 2018 at 9:49 AM Chris Fedde  wrote:

> I cannot emphasize enough how fragile the perhaps obvious regex based
> comparisons of timestamps can be. I second the approach demonstrated by
> Илья Рассадин above.  There are subtle and difficult to debug problems
> buried in timestamps.  Not least of which is locale ambiguity,
> discontinuities like daylight savings time, leap seconds, and more.  I
> second the recommendation to use Time::Piece.
> Doc is here: https://perldoc.perl.org/Time/Piece.html
>
>
> On Tue, Oct 23, 2018 at 11:42 PM Asad  wrote:
>
>> Thank you all for the reply it is working for me .
>>
>> 1) for  02/23/18 01:10:33  ==> I  am using the following regex
>>
>> \d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]
>>
>> 2) Feb 23 01:10:28 2018
>>
>> > I  am using the following regex :
>>
>> ([A-Z][a-z]{2}\s)([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4})
>>
>>
>> Both are working as expected I would like to know if these are good regex or 
>> it can be better , please suggest .
>>
>> Thanks,
>>
>>
>>
>> On Tue, Oct 23, 2018 at 12:14 PM Asad  wrote:
>>
>>> Hi All ,
>>>
>>> first hurdle is how do I extract this Feb 23 01:10:28 2018  from
>>> file1 which regex can I use ?
>>>
>>>  convert it into epoch
>>>
>>> then
>>>
>>>  regex for 02/23/18 01:10:33  is required  ?
>>>
>>> convert into epoch
>>>
>>>So if you can suggest the correct regex for both timestamps.
>>>
>>> Thanks,
>>>
>>> On Tue, Oct 23, 2018 at 12:11 PM Илья Рассадин 
>>> wrote:
>>>
>>>> use Time::Piece;
>>>>
>>>> my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S
>>>> %Y');
>>>>
>>>> my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y
>>>> %H:%M:%S');
>>>>
>>>> if ($t1 > $t2) { ... }
>>>> On 23/10/2018 09:17, Asad wrote:
>>>>
>>>> Hi All ,
>>>>
>>>> first hurdle is how do I extract this Feb 23 01:10:28 2018
>>>> from file1 which regex can I use ?
>>>>
>>>>  convert it into epoch
>>>>
>>>> then
>>>>
>>>>  regex for 02/23/18 01:10:33  is required  ?
>>>>
>>>> convert into epoch
>>>>
>>>>So if you can suggest the correct regex for both timestamps.
>>>>
>>>> Thanks,
>>>>
>>>> On Tue, Oct 23, 2018 at 11:21 AM Asad  wrote:
>>>>
>>>>> Thanks, I will do that. It was for perl .
>>>>>
>>>>> On Tue, Oct 23, 2018 at 10:42 AM Jim Gibson 
>>>>> wrote:
>>>>>
>>>>>> On Oct 22, 2018, at 9:12 PM, Asad  wrote:
>>>>>> >
>>>>>> > file1 :
>>>>>> > Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28
>>>>>> 2018
>>>>>> >
>>>>>> > Bootstrapping registry and package to current versions...done
>>>

Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Chris Fedde
I cannot emphasize enough how fragile the perhaps obvious regex based
comparisons of timestamps can be. I second the approach demonstrated by
Илья Рассадин above.  There are subtle and difficult to debug problems
buried in timestamps.  Not least of which is locale ambiguity,
discontinuities like daylight savings time, leap seconds, and more.  I
second the recommendation to use Time::Piece.
Doc is here: https://perldoc.perl.org/Time/Piece.html


On Tue, Oct 23, 2018 at 11:42 PM Asad  wrote:

> Thank you all for the reply it is working for me .
>
> 1) for  02/23/18 01:10:33  ==> I  am using the following regex
>
> \d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]
>
> 2) Feb 23 01:10:28 2018
>
> ====> I  am using the following regex :
>
> ([A-Z][a-z]{2}\s)([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4})
>
>
> Both are working as expected I would like to know if these are good regex or 
> it can be better , please suggest .
>
> Thanks,
>
>
>
> On Tue, Oct 23, 2018 at 12:14 PM Asad  wrote:
>
>> Hi All ,
>>
>> first hurdle is how do I extract this Feb 23 01:10:28 2018  from
>> file1 which regex can I use ?
>>
>>  convert it into epoch
>>
>> then
>>
>>      regex for 02/23/18 01:10:33  is required  ?
>>
>> convert into epoch
>>
>>So if you can suggest the correct regex for both timestamps.
>>
>> Thanks,
>>
>> On Tue, Oct 23, 2018 at 12:11 PM Илья Рассадин 
>> wrote:
>>
>>> use Time::Piece;
>>>
>>> my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S
>>> %Y');
>>>
>>> my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S');
>>>
>>> if ($t1 > $t2) { ... }
>>> On 23/10/2018 09:17, Asad wrote:
>>>
>>> Hi All ,
>>>
>>> first hurdle is how do I extract this Feb 23 01:10:28 2018  from
>>> file1 which regex can I use ?
>>>
>>>  convert it into epoch
>>>
>>> then
>>>
>>>  regex for 02/23/18 01:10:33  is required  ?
>>>
>>> convert into epoch
>>>
>>>So if you can suggest the correct regex for both timestamps.
>>>
>>> Thanks,
>>>
>>> On Tue, Oct 23, 2018 at 11:21 AM Asad  wrote:
>>>
>>>> Thanks, I will do that. It was for perl .
>>>>
>>>> On Tue, Oct 23, 2018 at 10:42 AM Jim Gibson 
>>>> wrote:
>>>>
>>>>> On Oct 22, 2018, at 9:12 PM, Asad  wrote:
>>>>> >
>>>>> > file1 :
>>>>> > Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28
>>>>> 2018
>>>>> >
>>>>> > Bootstrapping registry and package to current versions...done
>>>>> > statement ERR-2001: table is corrupt check for cause
>>>>> >
>>>>> > could not determine the current status.
>>>>> >
>>>>> > file2 :
>>>>> >
>>>>> >  LOG file opened at 02/03/18 01:11:05
>>>>> >
>>>>> > DUP-05004:   statement1
>>>>> > DUP-05007:   statement2
>>>>> >
>>>>> >
>>>>> >  LOG file opened at 02/03/18 01:11:14
>>>>> >
>>>>> > DUP-05004:   statement1
>>>>> >
>>>>> > DUP-05007:   statement2
>>>>> >
>>>>> >
>>>>> >  LOG file opened at 02/23/18 01:10:33
>>>>> >
>>>>> > DUP-05004:   statement1
>>>>> >
>>>>> > DUP-05007:   statement2
>>>>> >
>>>>> > I need to look for the ERR-2001 in file1 if it matches then go to
>>>>> file2 and print the message nearest to the timestamp found in file1 within
>>>>> two minutes of range .
>>>>> >
>>>>> > so in this case file1 :  Fri Feb 23 01:10:28 2018
>>>>> >range   file1 +2 mins :02/23/18 01:12:28
>>>>> > check in file 2 nearest to file1 and within range : 02/23/18
>>>>> 01:10:33
>>>>> >
>>>>> > how do i compare two timestamps in different format and within
>>>>> range  ?
>>>>>
>>>>> You would first convert the two timestamps to a common format,
>>>>> preferably one that used a numerical value to express times. I know of two
>>>>> such: the Unix epoch time that uses an integer to represent the number of
>>>>> seconds since 1 Jan 1970 UTM and the Julian date that uses a 
>>>>> floating-point
>>>>> number to represent the number of days since 1 Jan 4713 BCE.
>>>>>
>>>>> Are you looking for a Perl solution or a Python one?
>>>>>
>>>>> For Perl, you should investigate time and date modules available on
>>>>> CPAN, such as Date::Manip or Date::Calc.
>>>>>
>>>>>
>>>>
>>>> --
>>>> Asad Hasan
>>>> +91 9582111698
>>>>
>>>
>>>
>>> --
>>> Asad Hasan
>>> +91 9582111698
>>>
>>>
>>
>> --
>> Asad Hasan
>> +91 9582111698
>>
>
>
> --
> Asad Hasan
> +91 9582111698
>


Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Olivier
Hi,

> Thank you all for the reply it is working for me .
>
> 1) for 02/23/18 01:10:33 ==> I am using the following regex 
> \d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]
> 2) Feb 23 01:10:28 2018
> > I  am using the following regex :
> ([A-Z][a-z]{2}\s)([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4})
>
> Both are working as expected I would like to know if these are good regex or 
> it can be better , please suggest .

The regex seems to be working (I cannot recommend too much the
excellent tool TheRegex Coach).

But with the regex, you have only done half of the work: you still need
to be able to compare the date & time.

You should really go the route suggested earlier and use a Perl module
made for date manipulation, it will seve you hours of debugging; and you
will be able to convert any date into a timestamp (epoch) and simply
compare timestamps.

Regards,

Olivier

> Thanks,
>
> On Tue, Oct 23, 2018 at 12:14 PM Asad  wrote:
>
>  Hi All ,
>
>  first hurdle is how do I extract this Feb 23 01:10:28 2018 from file1 which 
> regex can I use ?
>
>  convert it into epoch 
>
>  then 
>
>  regex for 02/23/18 01:10:33 is required ?
>
>  convert into epoch
>
>  So if you can suggest the correct regex for both timestamps.
>
>  Thanks,
>
>  On Tue, Oct 23, 2018 at 12:11 PM Илья Рассадин  wrote:
>
>  use Time::Piece;
>
>  my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S %Y');
>
>  my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S');
>
>  if ($t1 > $t2) { ... }
>
>  On 23/10/2018 09:17, Asad wrote:
>
>  Hi All , 
>
>  first hurdle is how do I extract this Feb 23 01:10:28 2018 from file1 which 
> regex can
>  I use ?
>
>  convert it into epoch 
>
>  then 
>
>  regex for 02/23/18 01:10:33 is required ?
>
>  convert into epoch
>
>  So if you can suggest the correct regex for both timestamps.
>
>  Thanks,
>
>  On Tue, Oct 23, 2018 at 11:21 AM Asad  wrote:
>
>  Thanks, I will do that. It was for perl . 
>
>  On Tue, Oct 23, 2018 at 10:42 AM Jim Gibson 
>  wrote:
>
>  On Oct 22, 2018, at 9:12 PM, Asad 
>  wrote:
>  > 
>  > file1 :
>  > Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28 2018
>  > 
>  > Bootstrapping registry and package to current versions...done
>  > statement ERR-2001: table is corrupt check for cause 
>  > 
>  > could not determine the current status.
>  > 
>  > file2 :
>  > 
>  > LOG file opened at 02/03/18 01:11:05
>  > 
>  > DUP-05004: statement1
>  > DUP-05007: statement2
>  > 
>  > 
>  > LOG file opened at 02/03/18 01:11:14
>  > 
>  > DUP-05004: statement1
>  > 
>  > DUP-05007: statement2
>  > 
>  > 
>  > LOG file opened at 02/23/18 01:10:33
>  > 
>  > DUP-05004: statement1
>  > 
>  > DUP-05007: statement2
>  > 
>  > I need to look for the ERR-2001 in file1 if it matches then go to file2 and
>  print the message nearest to the timestamp found in file1 within two
>  minutes of range .
>  > 
>  > so in this case file1 : Fri Feb 23 01:10:28 2018
>  > range file1 +2 mins :02/23/18 01:12:28
>  > check in file 2 nearest to file1 and within range : 02/23/18 01:10:33 
>  > 
>  > how do i compare two timestamps in different format and within range
>  ?
>
>  You would first convert the two timestamps to a common format,
>  preferably one that used a numerical value to express times. I know of
>  two such: the Unix epoch time that uses an integer to represent the
>  number of seconds since 1 Jan 1970 UTM and the Julian date that uses a
>  floating-point number to represent the number of days since 1 Jan 4713
>  BCE.
>
>  Are you looking for a Perl solution or a Python one?
>
>  For Perl, you should investigate time and date modules available on
>  CPAN, such as Date::Manip or Date::Calc.
>
>  -- 
>  Asad Hasan
>  +91 9582111698
>
>  -- 
>  Asad Hasan
>  +91 9582111698
>
>  -- 
>  Asad Hasan
>  +91 9582111698

-- 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to compare timestamp in two different files(regex)

2018-10-23 Thread Asad
Thank you all for the reply it is working for me .

1) for  02/23/18 01:10:33  ==> I  am using the following regex

\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]

2) Feb 23 01:10:28 2018

> I  am using the following regex :

([A-Z][a-z]{2}\s)([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4})


Both are working as expected I would like to know if these are good
regex or it can be better , please suggest .

Thanks,



On Tue, Oct 23, 2018 at 12:14 PM Asad  wrote:

> Hi All ,
>
> first hurdle is how do I extract this Feb 23 01:10:28 2018  from
> file1 which regex can I use ?
>
>  convert it into epoch
>
>     then
>
>  regex for 02/23/18 01:10:33  is required  ?
>
> convert into epoch
>
>So if you can suggest the correct regex for both timestamps.
>
> Thanks,
>
> On Tue, Oct 23, 2018 at 12:11 PM Илья Рассадин 
> wrote:
>
>> use Time::Piece;
>>
>> my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S
>> %Y');
>>
>> my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S');
>>
>> if ($t1 > $t2) { ... }
>> On 23/10/2018 09:17, Asad wrote:
>>
>> Hi All ,
>>
>> first hurdle is how do I extract this Feb 23 01:10:28 2018  from
>> file1 which regex can I use ?
>>
>>  convert it into epoch
>>
>> then
>>
>>  regex for 02/23/18 01:10:33  is required  ?
>>
>> convert into epoch
>>
>>So if you can suggest the correct regex for both timestamps.
>>
>> Thanks,
>>
>> On Tue, Oct 23, 2018 at 11:21 AM Asad  wrote:
>>
>>> Thanks, I will do that. It was for perl .
>>>
>>> On Tue, Oct 23, 2018 at 10:42 AM Jim Gibson 
>>> wrote:
>>>
>>>> On Oct 22, 2018, at 9:12 PM, Asad  wrote:
>>>> >
>>>> > file1 :
>>>> > Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28
>>>> 2018
>>>> >
>>>> > Bootstrapping registry and package to current versions...done
>>>> > statement ERR-2001: table is corrupt check for cause
>>>> >
>>>> > could not determine the current status.
>>>> >
>>>> > file2 :
>>>> >
>>>> >  LOG file opened at 02/03/18 01:11:05
>>>> >
>>>> > DUP-05004:   statement1
>>>> > DUP-05007:   statement2
>>>> >
>>>> >
>>>> >  LOG file opened at 02/03/18 01:11:14
>>>> >
>>>> > DUP-05004:   statement1
>>>> >
>>>> > DUP-05007:   statement2
>>>> >
>>>> >
>>>> >  LOG file opened at 02/23/18 01:10:33
>>>> >
>>>> > DUP-05004:   statement1
>>>> >
>>>> > DUP-05007:   statement2
>>>> >
>>>> > I need to look for the ERR-2001 in file1 if it matches then go to
>>>> file2 and print the message nearest to the timestamp found in file1 within
>>>> two minutes of range .
>>>> >
>>>> > so in this case file1 :  Fri Feb 23 01:10:28 2018
>>>> >range   file1 +2 mins :02/23/18 01:12:28
>>>> > check in file 2 nearest to file1 and within range : 02/23/18
>>>> 01:10:33
>>>> >
>>>> > how do i compare two timestamps in different format and within range
>>>> ?
>>>>
>>>> You would first convert the two timestamps to a common format,
>>>> preferably one that used a numerical value to express times. I know of two
>>>> such: the Unix epoch time that uses an integer to represent the number of
>>>> seconds since 1 Jan 1970 UTM and the Julian date that uses a floating-point
>>>> number to represent the number of days since 1 Jan 4713 BCE.
>>>>
>>>> Are you looking for a Perl solution or a Python one?
>>>>
>>>> For Perl, you should investigate time and date modules available on
>>>> CPAN, such as Date::Manip or Date::Calc.
>>>>
>>>>
>>>
>>> --
>>> Asad Hasan
>>> +91 9582111698
>>>
>>
>>
>> --
>> Asad Hasan
>> +91 9582111698
>>
>>
>
> --
> Asad Hasan
> +91 9582111698
>


-- 
Asad Hasan
+91 9582111698


Re: How to compare timestamp in two different files(regex)

2018-10-23 Thread Andy Bach
> first hurdle is how do I extract this Feb 23 01:10:28 2018  from file1
which regex

Look at perldoc -f stat

 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  $atime,$mtime,$ctime,$blksize,$blocks)
  = stat($filename);

   Not all fields are supported on all filesystem types.  Here
are the meanings of the fields:

 0 dev  device number of filesystem
 1 ino  inode number
 2 mode file mode  (type and permissions)
 3 nlinknumber of (hard) links to the file
 4 uid  numeric user ID of file's owner
 5 gid  numeric group ID of file's owner
 6 rdev the device identifier (special files only)
 7 size total size of file, in bytes
 8 atimelast access time in seconds since the epoch
 9 mtimelast modify time in seconds since the epoch
10 ctimeinode change time in seconds since the epoch (*)
11 blksize  preferred block size for file system I/O
12 blocks   actual number of blocks allocated

   (The epoch was at 00:00 January 1, 1970 GMT.)
once you've got epoch time, you can (assuming they're both newer than
1/1/70 ;-), just do math with them. localtime() will convert
that to English.

On Tue, Oct 23, 2018 at 1:45 AM Asad  wrote:

> Hi All ,
>
> first hurdle is how do I extract this Feb 23 01:10:28 2018  from
> file1 which regex can I use ?
>
>  convert it into epoch
>
> then
>
>  regex for 02/23/18 01:10:33  is required  ?
>
> convert into epoch
>
>    So if you can suggest the correct regex for both timestamps.
>
> Thanks,
>
> On Tue, Oct 23, 2018 at 12:11 PM Илья Рассадин 
> wrote:
>
>> use Time::Piece;
>>
>> my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S
>> %Y');
>>
>> my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S');
>>
>> if ($t1 > $t2) { ... }
>> On 23/10/2018 09:17, Asad wrote:
>>
>> Hi All ,
>>
>> first hurdle is how do I extract this Feb 23 01:10:28 2018  from
>> file1 which regex can I use ?
>>
>>  convert it into epoch
>>
>> then
>>
>>  regex for 02/23/18 01:10:33  is required  ?
>>
>> convert into epoch
>>
>>So if you can suggest the correct regex for both timestamps.
>>
>> Thanks,
>>
>> On Tue, Oct 23, 2018 at 11:21 AM Asad  wrote:
>>
>>> Thanks, I will do that. It was for perl .
>>>
>>> On Tue, Oct 23, 2018 at 10:42 AM Jim Gibson 
>>> wrote:
>>>
>>>> On Oct 22, 2018, at 9:12 PM, Asad  wrote:
>>>> >
>>>> > file1 :
>>>> > Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28
>>>> 2018
>>>> >
>>>> > Bootstrapping registry and package to current versions...done
>>>> > statement ERR-2001: table is corrupt check for cause
>>>> >
>>>> > could not determine the current status.
>>>> >
>>>> > file2 :
>>>> >
>>>> >  LOG file opened at 02/03/18 01:11:05
>>>> >
>>>> > DUP-05004:   statement1
>>>> > DUP-05007:   statement2
>>>> >
>>>> >
>>>> >  LOG file opened at 02/03/18 01:11:14
>>>> >
>>>> > DUP-05004:   statement1
>>>> >
>>>> > DUP-05007:   statement2
>>>> >
>>>> >
>>>> >  LOG file opened at 02/23/18 01:10:33
>>>> >
>>>> > DUP-05004:   statement1
>>>> >
>>>> > DUP-05007:   statement2
>>>> >
>>>> > I need to look for the ERR-2001 in file1 if it matches then go to
>>>> file2 and print the message nearest to the timestamp found in file1 within
>>>> two minutes of range .
>>>> >
>>>> > so in this case file1 :  Fri Feb 23 01:10:28 2018
>>>> >range   file1 +2 mins :02/23/18 01:12:28
>>>> > check in file 2 nearest to file1 and within range : 02/23/18
>>>> 01:10:33
>>>> >
>>>> > how do i compare two timestamps in different format and within range
>>>> ?
>>>>
>>>> You would first convert the two timestamps to a common format,
>>>> preferably one that used a numerical value to express times. I know of two
>>>> such: the Unix epoch time that uses an integer to represent the number of
>>>> seconds since 1 Jan 1970 UTM and the Julian date that uses a floating-point
>>>> number to represent the number of days since 1 Jan 4713 BCE.
>>>>
>>>> Are you looking for a Perl solution or a Python one?
>>>>
>>>> For Perl, you should investigate time and date modules available on
>>>> CPAN, such as Date::Manip or Date::Calc.
>>>>
>>>>
>>>
>>> --
>>> Asad Hasan
>>> +91 9582111698
>>>
>>
>>
>> --
>> Asad Hasan
>> +91 9582111698
>>
>>
>
> --
> Asad Hasan
> +91 9582111698
>


-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: How to compare timestamp in two different files(regex)

2018-10-23 Thread Asad
Hi All ,

first hurdle is how do I extract this Feb 23 01:10:28 2018  from
file1 which regex can I use ?

 convert it into epoch

then

 regex for 02/23/18 01:10:33  is required  ?

convert into epoch

   So if you can suggest the correct regex for both timestamps.

Thanks,

On Tue, Oct 23, 2018 at 12:11 PM Илья Рассадин  wrote:

> use Time::Piece;
>
> my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S
> %Y');
>
> my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S');
>
> if ($t1 > $t2) { ... }
> On 23/10/2018 09:17, Asad wrote:
>
> Hi All ,
>
> first hurdle is how do I extract this Feb 23 01:10:28 2018  from
> file1 which regex can I use ?
>
>  convert it into epoch
>
> then
>
>  regex for 02/23/18 01:10:33  is required  ?
>
>     convert into epoch
>
>So if you can suggest the correct regex for both timestamps.
>
> Thanks,
>
> On Tue, Oct 23, 2018 at 11:21 AM Asad  wrote:
>
>> Thanks, I will do that. It was for perl .
>>
>> On Tue, Oct 23, 2018 at 10:42 AM Jim Gibson  wrote:
>>
>>> On Oct 22, 2018, at 9:12 PM, Asad  wrote:
>>> >
>>> > file1 :
>>> > Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28 2018
>>> >
>>> > Bootstrapping registry and package to current versions...done
>>> > statement ERR-2001: table is corrupt check for cause
>>> >
>>> > could not determine the current status.
>>> >
>>> > file2 :
>>> >
>>> >  LOG file opened at 02/03/18 01:11:05
>>> >
>>> > DUP-05004:   statement1
>>> > DUP-05007:   statement2
>>> >
>>> >
>>> >  LOG file opened at 02/03/18 01:11:14
>>> >
>>> > DUP-05004:   statement1
>>> >
>>> > DUP-05007:   statement2
>>> >
>>> >
>>> >  LOG file opened at 02/23/18 01:10:33
>>> >
>>> > DUP-05004:   statement1
>>> >
>>> > DUP-05007:   statement2
>>> >
>>> > I need to look for the ERR-2001 in file1 if it matches then go to
>>> file2 and print the message nearest to the timestamp found in file1 within
>>> two minutes of range .
>>> >
>>> > so in this case file1 :  Fri Feb 23 01:10:28 2018
>>> >range   file1 +2 mins :02/23/18 01:12:28
>>> > check in file 2 nearest to file1 and within range : 02/23/18
>>> 01:10:33
>>> >
>>> > how do i compare two timestamps in different format and within range  ?
>>>
>>> You would first convert the two timestamps to a common format,
>>> preferably one that used a numerical value to express times. I know of two
>>> such: the Unix epoch time that uses an integer to represent the number of
>>> seconds since 1 Jan 1970 UTM and the Julian date that uses a floating-point
>>> number to represent the number of days since 1 Jan 4713 BCE.
>>>
>>> Are you looking for a Perl solution or a Python one?
>>>
>>> For Perl, you should investigate time and date modules available on
>>> CPAN, such as Date::Manip or Date::Calc.
>>>
>>>
>>
>> --
>> Asad Hasan
>> +91 9582111698
>>
>
>
> --
> Asad Hasan
> +91 9582111698
>
>

-- 
Asad Hasan
+91 9582111698


Re: Regex for date

2018-08-25 Thread Chris Charley

"Asad"  wrote in message 
news:cag3lskh4dphjg18c-jxmo8bcqfd+vix5tep1ytsp4_6pd6z...@mail.gmail.com...
Hi All , 

  I need  a regex to match the date : Sat Aug 25 08:41:03 2018 and 
covert into a format :'%m/%d/%Y %H:%M:%S' 

Thanks, 


-- 

Asad Hasan
+91 9582111698

Hello Asad,

You could use Time::Piece to do this. (Although given a choice, I would use 
‘%Y/%m/%d %H:%M:%S’ which sorts naturally in a sorting situation)

#!/usr/bin/perl
use strict;
use warnings;
use Time::Piece;

my $d = 'Sat Aug 25 08:41:03 2018';

my $dt = Time::Piece->strptime($d, '%a %b %d %H:%M:%S %Y');

say $dt->strftime('%m/%d/%Y %H:%M:%S');

Re: Regex for date

2018-08-25 Thread Jim Gibson
Many Perl modules have been written to parse and manipulate dates and times. 
Some come with Perl; others are available at www.cpan.org.

Check out the Date::Manip, Date::Parse, or DateTime modules.

> On Aug 25, 2018, at 4:06 AM, Asad  wrote:
> 
> Hi All ,
> 
> I need  a regex to match the date : Sat Aug 25 08:41:03 2018 and 
> covert into a format : '%m/%d/%Y %H:%M:%S' 
> 
> Thanks, 
> 
> -- 
> Asad Hasan
> +91 9582111698



Jim Gibson

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex for date

2018-08-25 Thread Asad
Thanks, I'll check them out.

On Sat, Aug 25, 2018 at 4:53 PM Home Linux Info 
wrote:

>
> Hello,
>
> Maybe not the most beautiful regex out there, hey I'm a noob, but it does
> the job right:
> ([A-Z][a-z]{2}\s)|([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4})
> You can start from here and find a nicer form of this regex.
>
> On 8/25/18 2:06 PM, Asad wrote:
>
> Hi All ,
>
>   I need  a regex to match the date : Sat Aug 25 08:41:03 2018 and
> covert into a format : '%m/%d/%Y %H:%M:%S'
>
> Thanks,
>
> --
> Asad Hasan
> +91 9582111698
>
>
>

-- 
Asad Hasan
+91 9582111698


Re: Regex for date

2018-08-25 Thread Home Linux Info


Hello,

Maybe not the most beautiful regex out there, hey I'm a noob, but it 
does the job right:

([A-Z][a-z]{2}\s)|([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4})
You can start from here and find a nicer form of this regex.

On 8/25/18 2:06 PM, Asad wrote:

Hi All ,

          I need  a regex to match the date : Sat Aug 25 08:41:03 2018 
and covert into a format :  '%m/%d/%Y %H:%M:%S'


Thanks,

--
Asad Hasan
+91 9582111698




Re: Regex for date

2018-08-25 Thread Mike Flannigan


Really, no attempt to do it yourself?


Mike


On 8/25/2018 6:06 AM, beginners-digest-h...@perl.org wrote:


Hi All ,

          I need  a regex to match the date : Sat Aug 25 08:41:03 2018 
and covert into a format :  '%m/%d/%Y %H:%M:%S'


Thanks,

--
Asad Hasan




Regex for date

2018-08-25 Thread Asad
Hi All ,

  I need  a regex to match the date : Sat Aug 25 08:41:03 2018 and
covert into a format : '%m/%d/%Y %H:%M:%S'

Thanks,

-- 
Asad Hasan
+91 9582111698


Re: regex to get the rpm name version

2018-08-09 Thread Andy Bach
You can put your separators in there as literals to keep them out of
captures:

$ cat /tmp/ver.pl
#!perl

while () {
  if ( /([\w+-]{3,})-([.\d-]+)\./ ) {
 print "$1 - $2\n";
  }
print "$_\n";
}


__END__
binutils-2.23.52.0.1-12.el7.x86_64
compat-libcap1-1.10-3.el7.x86_64
compat-libstdc++-33-3.2.3-71.el7.i686

$ perl /tmp/ver.pl
binutils - 2.23.52.0.1-12
binutils-2.23.52.0.1-12.el7.x86_64

compat-libcap1 - 1.10-3
compat-libcap1-1.10-3.el7.x86_64

compat-libstdc++-33 - 3.2.3-71
compat-libstdc++-33-3.2.3-71.el7.i686

But you may want to look at the options for rpm listing. There are many and
they can specifically list the package version - you can create your own
format for the listings.

man rpm
   --qf|--queryformat QUERYFMT

   option, followed by the QUERYFMT format string.  Query formats are
modified versions of the standard printf(3) formatting. The format  is
   made up of static strings (which may include standard C character
escapes for newlines, tabs, and other special characters) and printf(3)
   type formatters.  As rpm already knows the type to print, the type
specifier must be omitted however, and replaced by  the  name  of  the
   header  tag to be printed, enclosed by {} characters. Tag names are
case insensitive, and the leading RPMTAG_ portion of the tag name may
   be omitted as well.


On Thu, Aug 9, 2018 at 4:32 PM, Home Linux Info 
wrote:

>
> Hello,
>
> You can begin with "*[a-zA-Z_+-]{3,}[0-9]*" to get the package name, it
> needs a little more work for right now it gets the last dash and first
> digit of package version. Then you can try "*([^a-zA-Z_+-]{3,})(.\d{1,})*
> ".
> The first regex gives the following result:
> *binutils-2*
> *compat-libcap1*
> *compat-libstdc++-3*
> Which is almost what you need while the second one is more exact as it
> gives you:
> *2.23.52.0.1-12*
> *1.10-3*
> *3.2.3-71*
> And that looks like exactly what you need.
>
> I'm no expert in regex but I like to experiment with it to see if I can
> extract some parts from a text / string using it.
>
> Jimmy (bash, perl and python total noob but trying to learn stuff).
>
> On 27.07.2018 15:54, Asad wrote:
>
> Hi All ,
>
>  I want to get a regex to actually get the rpm name and version
> for comparison :
>
>
> binutils-2.23.52.0.1-12.el7.x86_64",
> compat-libcap1-1.10-3.el7.x86_64"
> compat-libstdc++-33-3.2.3-71.el7.i686
>
> (^[a-zA-Z0-9\-]*)\-\d'
>
> First part of the regular expression is ^[a-zA-Z0-9\-]
>
> which means search for anything that begins with a letter
>
> (lower or upper) or a number up until you reach an
>
> hyphen sign (‘-‘).
>
> but it fails to match
>
> compat-libstdc++-33-3.2.3-71.el7.i686
>
> Please let me know what regex should i use to extract all 3
>
> rpms.
>
> Also let me know if there are web tools to build regex
>
> Good websites for regex tutorials.
>
> Thanks,
>
>
>
> --
> Asad Hasan
> +91 9582111698
>
>
>


-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: regex to get the rpm name version

2018-08-09 Thread Home Linux Info


Hello,

You can begin with "*[a-zA-Z_+-]{3,}[0-9]*" to get the package name, it 
needs a little more work for right now it gets the last dash and first 
digit of package version. Then you can try "*([^a-zA-Z_+-]{3,})(.\d{1,})*".

The first regex gives the following result:
/binutils-2//
//compat-libcap1//
//compat-libstdc++-3//
/Which is almost what you need while the second one is more exact as it 
gives you:

/2.23.52.0.1-12//
//1.10-3//
//3.2.3-71//
/And that looks like exactly what you need.

I'm no expert in regex but I like to experiment with it to see if I can 
extract some parts from a text / string using it.


Jimmy (bash, perl and python total noob but trying to learn stuff).

On 27.07.2018 15:54, Asad wrote:

Hi All ,

         I want to get a regex to actually get the rpm name and 
version for comparison :



binutils-2.23.52.0.1-12.el7.x86_64", compat-libcap1-1.10-3.el7.x86_64" 
compat-libstdc++-33-3.2.3-71.el7.i686 (^[a-zA-Z0-9\-]*)\-\d'

First part of the regular expression is ^[a-zA-Z0-9\-]
which means search for anything that begins with a letter
(lower or upper) or a number up until you reach an
hyphen sign (‘-‘).
but it fails to match
compat-libstdc++-33-3.2.3-71.el7.i686
Please let me know what regex should i use to extract all 3
rpms.
Also let me know if there are web tools to build regex
Good websites for regex tutorials.
Thanks,


--
Asad Hasan
+91 9582111698




Re: regex to get the rpm name version

2018-07-27 Thread Shlomi Fish
Hi Asad,

On Fri, 27 Jul 2018 18:24:39 +0530
Asad  wrote:

> Hi All ,
> 
>  I want to get a regex to actually get the rpm name and version for
> comparison :
> 
> 
> binutils-2.23.52.0.1-12.el7.x86_64",
> compat-libcap1-1.10-3.el7.x86_64"
> compat-libstdc++-33-3.2.3-71.el7.i686
> 
> (^[a-zA-Z0-9\-]*)\-\d'
> 
> First part of the regular expression is ^[a-zA-Z0-9\-]
> 
> which means search for anything that begins with a letter
> 
> (lower or upper) or a number up until you reach an
> 
> hyphen sign (‘-‘).
> 
> but it fails to match
> 
> compat-libstdc++-33-3.2.3-71.el7.i686
> 
> Please let me know what regex should i use to extract all 3
> 
> rpms.
> 
> Also let me know if there are web tools to build regex
> 
> Good websites for regex tutorials.
> 

for that, see:

* http://perl-begin.org/topics/regular-expressions/

* https://github.com/aloisdg/awesome-regex

* https://www.regular-expressions.info/


> 
> 
> 
> Thanks,
> 
> 
> 
> 
> 



-- 
-
Shlomi Fish   http://www.shlomifish.org/
https://youtu.be/GoEn1YfYTBM - Tiffany Alvord - “Fall Together”

C++ is complex, complexifying and complexified.
(With apologies to the Oxford English Dictionary).
— http://www.shlomifish.org/humour.html

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex to get the rpm name version

2018-07-27 Thread Chas. Owens
But if you have to use a regex, I suggest using the /x  modifier to make it
easier to read an maintain the regex:

#!/usr/bin/perl

use strict;
use warnings;

for my $s (qw/binutils-2.23.52.0.1-12.el7.x86_64
compat-libcap1-1.10-3.el7.x86_64 compat-libstdc++-33-3.2.3-71.el7.i686/) {
my ($name, $version, $build) = $s =~ m{
^ (.*) # name
- (.*) # version
- ([0-9]+) # build
[.] [^.]+  # os
[.] [^.]+ \z  # architecture
}x;
print "n $name v $version b $build\n";
}

On Fri, Jul 27, 2018 at 9:14 AM Chas. Owens  wrote:

> I don't think a regex is the simplest and most maintainable way to get
> this information.  I think it is probably better to take advantage of the
> structure of the string to discard and find information:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> for my $s (qw/binutils-2.23.52.0.1-12.el7.x86_64
> compat-libcap1-1.10-3.el7.x86_64 compat-libstdc++-33-3.2.3-71.el7.i686/) {
> my @dots = split /\,/, $s;
> pop @dots; #get rid of architecture
> pop @dots; #get rid of os
> my $name_and_version = join "", @dots;
> my @dashes = split /-/, $s;
> my $build = pop @dashes;
> my $version = pop @dashes;
> my $name = join "-", @dashes;
> print "n $name v $version b $build\n";
> }
>
>
>
> On Fri, Jul 27, 2018 at 8:57 AM Asad  wrote:
>
>> Hi All ,
>>
>>  I want to get a regex to actually get the rpm name and version
>> for comparison :
>>
>>
>> binutils-2.23.52.0.1-12.el7.x86_64",
>> compat-libcap1-1.10-3.el7.x86_64"
>> compat-libstdc++-33-3.2.3-71.el7.i686
>>
>> (^[a-zA-Z0-9\-]*)\-\d'
>>
>> First part of the regular expression is ^[a-zA-Z0-9\-]
>>
>> which means search for anything that begins with a letter
>>
>> (lower or upper) or a number up until you reach an
>>
>> hyphen sign (‘-‘).
>>
>> but it fails to match
>>
>> compat-libstdc++-33-3.2.3-71.el7.i686
>>
>> Please let me know what regex should i use to extract all 3
>>
>> rpms.
>>
>> Also let me know if there are web tools to build regex
>>
>> Good websites for regex tutorials.
>>
>>
>>
>>
>> Thanks,
>>
>>
>>
>>
>>
>> --
>> Asad Hasan
>> +91 9582111698 <+91%2095821%2011698>
>>
>


RE: regex to get the rpm name version

2018-07-27 Thread Duncan Ferguson
I would suggest you change your approach and user the query mode of RPM to get 
your information instead of build up a regexp:

rpm -qa --queryformat "%{NAME}\n"

  Duncs

From: Asad [mailto:asad.hasan2...@gmail.com]
Sent: 27 July 2018 13:55
To: beginners@perl.org
Subject: regex to get the rpm name version

Hi All ,

 I want to get a regex to actually get the rpm name and version for 
comparison :



binutils-2.23.52.0.1-12.el7.x86_64",

compat-libcap1-1.10-3.el7.x86_64"

compat-libstdc++-33-3.2.3-71.el7.i686



(^[a-zA-Z0-9\-]*)\-\d'

First part of the regular expression is ^[a-zA-Z0-9\-]

which means search for anything that begins with a letter

(lower or upper) or a number up until you reach an

hyphen sign (‘-‘).



but it fails to match

compat-libstdc++-33-3.2.3-71.el7.i686

Please let me know what regex should i use to extract all 3

rpms.

Also let me know if there are web tools to build regex

Good websites for regex tutorials.







Thanks,









--
Asad Hasan
+91 9582111698


Re: regex to get the rpm name version

2018-07-27 Thread Chas. Owens
I don't think a regex is the simplest and most maintainable way to get this
information.  I think it is probably better to take advantage of the
structure of the string to discard and find information:

#!/usr/bin/perl

use strict;
use warnings;

for my $s (qw/binutils-2.23.52.0.1-12.el7.x86_64
compat-libcap1-1.10-3.el7.x86_64 compat-libstdc++-33-3.2.3-71.el7.i686/) {
my @dots = split /\,/, $s;
pop @dots; #get rid of architecture
pop @dots; #get rid of os
my $name_and_version = join "", @dots;
my @dashes = split /-/, $s;
my $build = pop @dashes;
my $version = pop @dashes;
my $name = join "-", @dashes;
print "n $name v $version b $build\n";
}



On Fri, Jul 27, 2018 at 8:57 AM Asad  wrote:

> Hi All ,
>
>  I want to get a regex to actually get the rpm name and version
> for comparison :
>
>
> binutils-2.23.52.0.1-12.el7.x86_64",
> compat-libcap1-1.10-3.el7.x86_64"
> compat-libstdc++-33-3.2.3-71.el7.i686
>
> (^[a-zA-Z0-9\-]*)\-\d'
>
> First part of the regular expression is ^[a-zA-Z0-9\-]
>
> which means search for anything that begins with a letter
>
> (lower or upper) or a number up until you reach an
>
> hyphen sign (‘-‘).
>
> but it fails to match
>
> compat-libstdc++-33-3.2.3-71.el7.i686
>
> Please let me know what regex should i use to extract all 3
>
> rpms.
>
> Also let me know if there are web tools to build regex
>
> Good websites for regex tutorials.
>
>
>
>
> Thanks,
>
>
>
>
>
> --
> Asad Hasan
> +91 9582111698 <+91%2095821%2011698>
>


regex to get the rpm name version

2018-07-27 Thread Asad
Hi All ,

 I want to get a regex to actually get the rpm name and version for
comparison :


binutils-2.23.52.0.1-12.el7.x86_64",
compat-libcap1-1.10-3.el7.x86_64"
compat-libstdc++-33-3.2.3-71.el7.i686

(^[a-zA-Z0-9\-]*)\-\d'

First part of the regular expression is ^[a-zA-Z0-9\-]

which means search for anything that begins with a letter

(lower or upper) or a number up until you reach an

hyphen sign (‘-‘).

but it fails to match

compat-libstdc++-33-3.2.3-71.el7.i686

Please let me know what regex should i use to extract all 3

rpms.

Also let me know if there are web tools to build regex

Good websites for regex tutorials.




Thanks,





-- 
Asad Hasan
+91 9582111698


Re: regex matches Chinese characters

2018-07-26 Thread Shlomi Fish
Hi Lauren,

On Fri, 27 Jul 2018 11:28:42 +0800
"Lauren C."  wrote:

> greetings,
> 
> I was doing the log statistics stuff using perl.
> There are chinese characters in log items.
> I tried with regex to match them, but got no luck.
> 
> $ perl -mstrict  -le 'my $char="汉语"; print "it is chinese" if $char =~ 
> /\p{Han}+/'
> 
> $ perl -mstrict -mutf8 -le 'my $char="汉语"; print "it is chinese" if 
> $char =~ /\p{Han}+/'
> 
> both output nothing.
> 
> My terminal is UTF-8:
> 

According to http://perldoc.perl.org/perlrun.html , you probably need -Mstrict
and -Mutf8 instead of the lowercase -m, so "sub import" will get called:

shlomif@telaviv1:~$ perl -Mstrict -Mutf8 -le 'my $char="汉语"; print "it is
chinese" if $char =~ /\p{Han}+/'
it is chinese
shlomif@telaviv1:~$ 

HTH,

Shlomi

> $ locale
> LANG=en_US.UTF-8
> LANGUAGE=
> LC_CTYPE="en_US.UTF-8"
> LC_NUMERIC="en_US.UTF-8"
> LC_TIME="en_US.UTF-8"
> LC_COLLATE="en_US.UTF-8"
> LC_MONETARY="en_US.UTF-8"
> LC_MESSAGES="en_US.UTF-8"
> LC_PAPER="en_US.UTF-8"
> LC_NAME="en_US.UTF-8"
> LC_ADDRESS="en_US.UTF-8"
> LC_TELEPHONE="en_US.UTF-8"
> LC_MEASUREMENT="en_US.UTF-8"
> LC_IDENTIFICATION="en_US.UTF-8"
> LC_ALL=
> 
> 
> Can you help? thanks in advance.
> 



-- 
-
Shlomi Fish   http://www.shlomifish.org/
https://github.com/sindresorhus/awesome - curated list of lists

Cats are smarter than dogs. You can’t get eight cats to pull a sled through
snow.— Source unknown, via Nadav Har’El.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex matches Chinese characters

2018-07-26 Thread Lauren C.

oops that's perfect. thanks Shlomi.

On 2018/7/27 星期五 PM 1:26, Shlomi Fish wrote:

Hi Lauren,

On Fri, 27 Jul 2018 11:28:42 +0800
"Lauren C."  wrote:


greetings,

I was doing the log statistics stuff using perl.
There are chinese characters in log items.
I tried with regex to match them, but got no luck.

$ perl -mstrict  -le 'my $char="汉语"; print "it is chinese" if $char =~
/\p{Han}+/'

$ perl -mstrict -mutf8 -le 'my $char="汉语"; print "it is chinese" if
$char =~ /\p{Han}+/'

both output nothing.

My terminal is UTF-8:



According to http://perldoc.perl.org/perlrun.html , you probably need -Mstrict
and -Mutf8 instead of the lowercase -m, so "sub import" will get called:

shlomif@telaviv1:~$ perl -Mstrict -Mutf8 -le 'my $char="汉语"; print "it is
chinese" if $char =~ /\p{Han}+/'
it is chinese
shlomif@telaviv1:~$

HTH,

Shlomi


$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=


Can you help? thanks in advance.







--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




regex matches Chinese characters

2018-07-26 Thread Lauren C.

greetings,

I was doing the log statistics stuff using perl.
There are chinese characters in log items.
I tried with regex to match them, but got no luck.

$ perl -mstrict  -le 'my $char="汉语"; print "it is chinese" if $char =~ 
/\p{Han}+/'


$ perl -mstrict -mutf8 -le 'my $char="汉语"; print "it is chinese" if 
$char =~ /\p{Han}+/'


both output nothing.

My terminal is UTF-8:

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=


Can you help? thanks in advance.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help with another regex

2018-07-17 Thread Lauren C.
I think reading the official tutorial from begin is not that comfortable 
to a newbie. I bought a book "Learning Perl, 6th Edition" for studying 
step by step. thanks.



On 2018/7/18 星期三 AM 9:08, Uri Guttman wrote:
also i always recommend reading the entire perl FAQ as there are many 
regex tips and plenty of other useful stuff in them. and i mean the 
entire FAQ!! again, skip if you don't get something but come back later 
on to read it.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help with another regex

2018-07-17 Thread Uri Guttman

On 07/17/2018 08:57 PM, Lauren C. wrote:

I did read them, but got no deep impression unless I met the issue. :)



not sure what kind of deep impression you need! :)

a key thing with docs is rereading them. read them once quickly all the 
way through to get a sense of the whole picture. read again but more 
slowly to learn the key things and practice them. then reread sections 
you need to know better as the core stuff will be somewhat familiar by 
then and you can delve deeper. and after you are done with the tutorial, 
read the full reference doc on the subject! the regex reference is very 
long and deep and you should follow the same pattern. don't be dismayed 
if you don't understand some topics. just skim and/or skip them. but get 
into the topics you already know from the tute as you will learn more 
about them. even experienced pros will go back to the docs without shame.


also i always recommend reading the entire perl FAQ as there are many 
regex tips and plenty of other useful stuff in them. and i mean the 
entire FAQ!! again, skip if you don't get something but come back later 
on to read it.


uri

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help with another regex

2018-07-17 Thread Lauren C.

I did read them, but got no deep impression unless I met the issue. :)

Uri Guttman 写道:

On 07/17/2018 08:46 PM, Lauren C. wrote:

Thanks Gil. I think i know the difference of "\w+" and "\w*" now.



lauren, did you read the perlretut document? if not, you should. it 
covers quantifiers early on as they are one of the fundamental features 
of regexes. a key thing to learn is the {m,n} quantifier as it can do 
any number of repeats. the *, + and ? quantifiers are just shortcuts:


     ? is {0,1}    0 or 1
     * is {0,}    0 or more
     + is {1,}    1 or more

those are used so often they should become ingrained in your brain!

uri



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help with another regex

2018-07-17 Thread Uri Guttman

On 07/17/2018 08:46 PM, Lauren C. wrote:

Thanks Gil. I think i know the difference of "\w+" and "\w*" now.



lauren, did you read the perlretut document? if not, you should. it 
covers quantifiers early on as they are one of the fundamental features 
of regexes. a key thing to learn is the {m,n} quantifier as it can do 
any number of repeats. the *, + and ? quantifiers are just shortcuts:


    ? is {0,1}    0 or 1
    * is {0,}    0 or more
    + is {1,}    1 or more

those are used so often they should become ingrained in your brain!

uri

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help with another regex

2018-07-17 Thread Lauren C.

yeah you explain that well. thanks.

Andy Bach 写道:

 > But it doesn't work for this case:

$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'

 > it expects 1 returned.

Well, assuming you mean it shouldn't match as $x starts with a slash and 
the RE doesn't - you're on the right path.  The reason is, the match 
goes anywhere, it is "unanchored" so Perl happily says, "walking" down 
$x saying:
"slash? nope. "p"? match! "a" match!! ... slash? yay! one or more ("+") 
word chars ("\w")? Aw, fail"


so, actually that RE fails:
$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'
[crickets]
as there's not even 1 "\w"
$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w}'


zero or more ("*") works
$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w*}'
1

as does none
$ perl -le '$x="/path/"; print 1 if $x=~m{path/}'
1

and adding the initial "/" to the RE still works:
$ perl -le '$x="/path/"; print 1 if $x=~m{/path/}'
1

but if you'd anchored ("^" - zero-width "at the beginning of the string" 
must be at the begining of the RE) your RE would fail too:

$ perl -le '$x="/path/"; print 1 if $x=~m{^path/}'

because the RE starts w/ "p" and the $x starts with slash.


On Tue, Jul 17, 2018 at 6:56 AM, Lauren C. > wrote:


Hello,

I want to match:

/path/
/path/123
/path/abc

but /path/?xxx  should not be matched.

This works:

$ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}'
1


this works too:

$ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}'


But it doesn't work for this case:

$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'

it expects 1 returned.

Can you help? thanks.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org


For additional commands, e-mail: beginners-h...@perl.org

http://learn.perl.org/





--

a

Andy Bach,
afb...@gmail.com 
608 658-1890 cell
608 261-5738 wk


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help with another regex

2018-07-17 Thread Lauren C.

Thanks Gil. I think i know the difference of "\w+" and "\w*" now.


Gil Magno 写道:

2018-07-17 19:56:59 +0800 Lauren C.:

Hello,

I want to match:

/path/
/path/123
/path/abc

but /path/?xxx  should not be matched.

This works:

$ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}'
1


this works too:

$ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}'


But it doesn't work for this case:

$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'


 From "perlintro":

 Quantifier * : zero or more of the previous thing.
 Quantifier + : one or more of the previous thing.

So "/path/" won't match m{path/\w+} because this regex wants "one or more \w" at that 
position, which the string doesn't have. If you use m{path/\w*} (note the asterisk) then you're saying 
"zero or more \w" at that position, and it'll match.


it expects 1 returned.

Can you help? thanks.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help with another regex

2018-07-17 Thread Andy Bach
> But it doesn't work for this case:

$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'

> it expects 1 returned.

Well, assuming you mean it shouldn't match as $x starts with a slash and
the RE doesn't - you're on the right path.  The reason is, the match goes
anywhere, it is "unanchored" so Perl happily says, "walking" down $x saying:
"slash? nope. "p"? match! "a" match!! ... slash? yay! one or more ("+")
word chars ("\w")? Aw, fail"

so, actually that RE fails:
$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'
[crickets]
as there's not even 1 "\w"
$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w}'


zero or more ("*") works
$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w*}'
1

as does none
$ perl -le '$x="/path/"; print 1 if $x=~m{path/}'
1

and adding the initial "/" to the RE still works:
$ perl -le '$x="/path/"; print 1 if $x=~m{/path/}'
1

but if you'd anchored ("^" - zero-width "at the beginning of the string"
must be at the begining of the RE) your RE would fail too:
$ perl -le '$x="/path/"; print 1 if $x=~m{^path/}'

because the RE starts w/ "p" and the $x starts with slash.


On Tue, Jul 17, 2018 at 6:56 AM, Lauren C.  wrote:

> Hello,
>
> I want to match:
>
> /path/
> /path/123
> /path/abc
>
> but /path/?xxx  should not be matched.
>
> This works:
>
> $ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}'
> 1
>
>
> this works too:
>
> $ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}'
>
>
> But it doesn't work for this case:
>
> $ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'
>
> it expects 1 returned.
>
> Can you help? thanks.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: help with another regex

2018-07-17 Thread Gil Magno
2018-07-17 19:56:59 +0800 Lauren C.:
> Hello,
> 
> I want to match:
> 
> /path/
> /path/123
> /path/abc
> 
> but /path/?xxx  should not be matched.
> 
> This works:
> 
> $ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}'
> 1
> 
> 
> this works too:
> 
> $ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}'
> 
> 
> But it doesn't work for this case:
> 
> $ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'

From "perlintro":

Quantifier * : zero or more of the previous thing.
Quantifier + : one or more of the previous thing.

So "/path/" won't match m{path/\w+} because this regex wants "one or more \w" 
at that position, which the string doesn't have. If you use m{path/\w*} (note 
the asterisk) then you're saying "zero or more \w" at that position, and it'll 
match.

> it expects 1 returned.
> 
> Can you help? thanks.
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 


signature.asc
Description: Digital signature


Re: help with another regex

2018-07-17 Thread Илья Рассадин

Hi!

I think, m{path/(\w+)?/?$} regex can solve your problem.

In general, to parse URL, you can use official regex from rfc3986 (see 
Appendix B for rfc3986)


regex is

^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
$2 is protocol
$4 is host
$5 is path
$7 is query
$9 is fragment.

Another approach is to use some of cpan modules to parse URI.

For example, https://metacpan.org/pod/URI


On 7/17/18 2:56 PM, Lauren C. wrote:

Hello,

I want to match:

/path/
/path/123
/path/abc

but /path/?xxx  should not be matched.

This works:

$ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}'
1


this works too:

$ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}'


But it doesn't work for this case:

$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'

it expects 1 returned.

Can you help? thanks.



help with another regex

2018-07-17 Thread Lauren C.

Hello,

I want to match:

/path/
/path/123
/path/abc

but /path/?xxx  should not be matched.

This works:

$ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}'
1


this works too:

$ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}'


But it doesn't work for this case:

$ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'

it expects 1 returned.

Can you help? thanks.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex for date format

2018-06-29 Thread Mike Martin
Worked perfectly thanks, uri, and same technique works perfectly in
postgresql regexp_replace for info

On 29 June 2018 at 16:18, Mike Martin  wrote:

> Thanks
>
>
> On Fri, 29 Jun 2018, 15:48 Uri Guttman,  wrote:
>
>> On 06/29/2018 10:41 AM, Mike Martin wrote:
>>
>> sorry
>> -mm-dd hh:mm:ss.dd
>> eg:
>> 2018-01-01 12-45-10-456789 to
>> 2018-01-01 12:45:10.456789
>>
>>
>>
>> please reply to the list and not to me!
>>
>> then why did you want lookbehind? this is very easy if you just grab the
>> time parts and reassemble them as you want. 
>>
>> $stamp =~ s/\s(\d\d)-(\d\d)-(\d\d)-/ $1:$2:$3./ ;
>>
>> it uses the space to mark where the time part starts.
>>
>> uri
>>
>>
>>


Re: Regex for date format

2018-06-29 Thread Mike Martin
Thanks

On Fri, 29 Jun 2018, 15:48 Uri Guttman,  wrote:

> On 06/29/2018 10:41 AM, Mike Martin wrote:
>
> sorry
> -mm-dd hh:mm:ss.dd
> eg:
> 2018-01-01 12-45-10-456789 to
> 2018-01-01 12:45:10.456789
>
>
>
> please reply to the list and not to me!
>
> then why did you want lookbehind? this is very easy if you just grab the
> time parts and reassemble them as you want. 
>
> $stamp =~ s/\s(\d\d)-(\d\d)-(\d\d)-/ $1:$2:$3./ ;
>
> it uses the space to mark where the time part starts.
>
> uri
>
>
>


Re: Regex for date format

2018-06-29 Thread Uri Guttman

On 06/29/2018 10:41 AM, Mike Martin wrote:

sorry
-mm-dd hh:mm:ss.dd
eg:
2018-01-01 12-45-10-456789 to
2018-01-01 12:45:10.456789




please reply to the list and not to me!

then why did you want lookbehind? this is very easy if you just grab the 
time parts and reassemble them as you want. 


    $stamp =~ s/\s(\d\d)-(\d\d)-(\d\d)-/ $1:$2:$3./ ;

it uses the space to mark where the time part starts.

uri




Re: Regex for date format

2018-06-29 Thread Uri Guttman

On 06/29/2018 09:32 AM, Mike Martin wrote:

Hi
I am trying to convert a string of the format
2018-01-01 16-45-21-654278

to a proper timestamp string

so basically I want to replace all -  after the date part


i am not sure what you are trying to do. show the after text that you 
want. a proper timestamp string is not specific enough.


if you want to really parse that string, then use Time::Piece and its 
strptime sub which can parse pretty much any time/date string.


uri

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Regex for date format

2018-06-29 Thread Mike Martin
Hi
I am trying to convert a string of the format
2018-01-01 16-45-21-654278

to a proper timestamp string

so basically I want to replace all -  after the date part

I am getting a bit stuck, lookbehind doesnt seem to work as it includes the
lookbehind on every occurence
last attempt is
s/(?<= )-/:/g;

any help appreciated

Mike


Re: regex with HEX ascii chars

2018-04-15 Thread Mike Flannigan


Try:
binmode(HANDLE)
before reading the file.
HANDLE is your filehandle.


If that doesn't work you might want to supply the
text file and a sample script.


Mike


On 4/12/2018 12:04 PM, beginners-digest-h...@perl.org wrote:


I have a text file (created by  pdftotext) that I've imported into my script.

It contains ASCII characters 251 for crosses and 252 for ticks.  If I load the
file in gvim and do :as

it reports the characters as

 251, Hex 00fb, Octal 373
 252, hex 00fc, Octal 374

However, when I try to seacch for it using

if ($line=~/[\xfb|\xfc]/) {

or even just

if ($line=~/\xfb/) {

it always fails.  What am I doing wrong?

Gary




Re: regex with HEX ascii chars

2018-04-13 Thread John W. Krahn
On Thu, 2018-04-12 at 17:26 +0100, Gary Stainburn wrote:
> I have a text file (created by  pdftotext) that I've imported into my
> script.
> 
> It contains ASCII characters 251 for crosses and 252 for ticks.

ASCII defines 128 characters so those characters are not ASCII.


John

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex with HEX ascii chars

2018-04-13 Thread Gary Stainburn
On Thursday 12 April 2018 19:53:16 Shlomi Fish wrote:
> Perhaps see http://perldoc.perl.org/perlunitut.html - you may need to read
> the file as binary or iso8859-1 or whatever. Also see

Thanks for this Shlomi. I have looked into that before briefly when doing http 
gets and reading office documents, but this time I didn't think I was going 
to need this.

> https://github.com/shlomif/how-to-share-code-online and read what Andy
> noted.

I thought the problem with my concepts rather than the program itself.  The 
following code shows that I was wrong.

#!/usr/bin/perl 

use strict;
use warnings;

my $line="A û ü  û";
my @arr=($line=~/(\xc3.)/g);
my $tick="\xc3\xbc";
my $cross="\xc3\xbb";

foreach my $c (split //,$line) {
  printf "%s = %X %d\n",$c,ord($c),ord($c);
}
if ($line=~/\xc3\xbb/) { print "true\n";}
foreach my $a (@arr) {
  print "start\n";
  if ($a eq $tick)  { print "tick\n";}
  if ($a eq $cross) { print "cross\n";}
}

[root@lou inet]# ./t1
A = 41 65
  = 20 32
� = C3 195
� = BB 187
  = 20 32
� = C3 195
� = BC 188
  = 20 32
  = 20 32
� = C3 195
� = BB 187
true
start
cross
start
tick
start
cross
[root@lou inet]# 

When I went back to gvim I noticed that it started showing two column values 
as as go past these fields, which should have given me a clue.

My production code now includes the following working code:

my $tick="\xc3\xbc";
my $cross="\xc3\xbb";

my @ticks=($line=~/(\xc3.)/g);
if (scalar(@ticks) == 5) {
  if ($ticks[0] eq $tick) {$job{sj_mot}='true';}
  if ($ticks[1] eq $tick) {$wuw='true'; $job{sj_wait}=20;}
  if ($ticks[2] eq $tick) {$job{sj_c_car}='true';}
  # 3 = advisor which we don't use
  if ($ticks[4] eq $tick) {$job{sj_wait}=30;}
} else {
  debugprint(1,"incorrect tick/cross count returned");
}

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex with HEX ascii chars

2018-04-12 Thread Shlomi Fish
On Thu, 12 Apr 2018 17:26:57 +0100
Gary Stainburn  wrote:

> I have a text file (created by  pdftotext) that I've imported into my script.
> 
> It contains ASCII characters 251 for crosses and 252 for ticks.  If I load
> the file in gvim and do :as
> 
> it reports the characters as 
> 
>  251, Hex 00fb, Octal 373
>  252, hex 00fc, Octal 374
> 
> However, when I try to seacch for it using
> 
> if ($line=~/[\xfb|\xfc]/) {
> 
> or even just 
> 
> if ($line=~/\xfb/) { 
> 
> it always fails.  What am I doing wrong?
> 

Perhaps see http://perldoc.perl.org/perlunitut.html - you may need to read the
file as binary or iso8859-1 or whatever. Also see
https://github.com/shlomif/how-to-share-code-online and read what Andy noted.

> Gary
> 



-- 
-
Shlomi Fish   http://www.shlomifish.org/
https://github.com/shlomif/what-you-should-know-about-automated-testing

It’s easier to port a shell than a shell script.
— http://en.wikiquote.org/wiki/Larry_Wall

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex with HEX ascii chars

2018-04-12 Thread Andy Bach
> However, when I try to seacch for it using

if ($line=~/[\xfb|\xfc]/) {

Note, you're mixing the character class " [ab] " with grouping alternative
pipe "  (  a | b ) " here

> or even just

if ($line=~/\xfb/) {

Dunno, works here:
$ perl -e '$line = "hi" . chr 251 . "ho" . chr 252 ; if
($line=~/[\xfb\xfc]/) { print "yep" } print "\n"'
yep
$ perl -e '$line = "hi" . chr 250 . "ho" . chr 253 ; if
($line=~/[\xfb\xfc]/) { print "yep" } print "\n"'
[crickets]


So, I'd guess your $line doesn't have a \xfb or \xfc in it at the time of
the test.
$ perl -e '$line = "hi" . chr 251 . "ho" . chr 253 ; if
($line=~/([\xfb\xfc])/) { print "yep: $1" } print "\n"' | od -c
000   y   e   p   : 373  \n
007


On Thu, Apr 12, 2018 at 11:26 AM, Gary Stainburn <
gary.stainb...@ringways.co.uk> wrote:

> I have a text file (created by  pdftotext) that I've imported into my
> script.
>
> It contains ASCII characters 251 for crosses and 252 for ticks.  If I load
> the
> file in gvim and do :as
>
> it reports the characters as
>
>  251, Hex 00fb, Octal 373
>  252, hex 00fc, Octal 374
>
> However, when I try to seacch for it using
>
> if ($line=~/[\xfb|\xfc]/) {
>
> or even just
>
> if ($line=~/\xfb/) {
>
> it always fails.  What am I doing wrong?
>
> Gary
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


regex with HEX ascii chars

2018-04-12 Thread Gary Stainburn
I have a text file (created by  pdftotext) that I've imported into my script.

It contains ASCII characters 251 for crosses and 252 for ticks.  If I load the 
file in gvim and do :as

it reports the characters as 

 251, Hex 00fb, Octal 373
 252, hex 00fc, Octal 374

However, when I try to seacch for it using

if ($line=~/[\xfb|\xfc]/) {

or even just 

if ($line=~/\xfb/) { 

it always fails.  What am I doing wrong?

Gary

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: interesting regex delimiters

2017-02-25 Thread Andrew Solomon
Thanks Chas., that's interesting! Here's my summary of what I've learnt
from this:

1. The regex

$foo =~ "\Asome string\Z"

is equivalent to

$bar = "\Asome string\Z"; # ends up as 'Asome stringB' with a warning
$foo =~ /$bar/;

i.e evaluate the string first and then stick it into the regex delimiters.

2. I'd never seen m?? before so if anyone else wants a good description and
context for usage see

http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators   (search
for ?PATTERN?)
and http://perldoc.perl.org/functions/continue.html


Andrew



On Fri, Feb 24, 2017 at 1:50 PM, Chas. Owens <chas.ow...@gmail.com> wrote:

> Be careful, it isn't actually a regex; it is a string that will be
> compiled to a regex.  You can see one difference here:
>
> #!/usr/bin/perl
>
> use v5.20;
> use warnings;
>
> say "string matches:";
> for my $s ("foo", "AfooZ") {
> say "\t$s: ", $s =~ "\Afoo\Z" ? "true" : "false";
> }
>
> say "regex matches:";
> for my $s ("foo", "AfooZ") {
> say "\t$s: ", $s =~ /\Afoo\Z/ ? "true" : "false";
> }
>
> which outputs
>
> Unrecognized escape \A passed through at t.pl line 8.
> Unrecognized escape \Z passed through at t.pl line 8.
> string matches:
> foo: false
> AfooZ: true
> regex matches:
> foo: true
> AfooZ: false
>
> To my knowledge, the only delimiters that do not require m or qr before
> them are // and ??; however, they are not equivalent (and ?? must be m?? as
> of Perl 5.22).  The m?? operator only matches the first time it sees a
> pattern and then will not match again until reset is called:
>
> #!/usr/bin/perl
>
> use v5.18;
> use warnings;
>
> for ("fo", "foo", "fooo", "f") {
> my ($match) = ?(fo+)?;
> say $match // "no match";
> if (/fooo/) {
> reset;
> }
> }
>
> Which outputs
>
> Use of ?PATTERN? without explicit operator is deprecated at t.pl line 7.
> fo
> no match
> no match
> f
>
>
> On Thu, Feb 23, 2017 at 6:53 PM Andrew Solomon <and...@geekuni.com> wrote:
>
>> Thanks Uri!
>>
>> On Thu, Feb 23, 2017 at 10:32 PM, Uri Guttman <u...@stemsystems.com>
>> wrote:
>>
>> On 02/23/2017 05:19 PM, Andrew Solomon wrote:
>>
>> Running Perl 18.2 I was surprised to discover that I can use single and
>> double quotes as regex delimiters without the 'm' operator.
>>
>> For example, instead of writing
>>
>> "/usr/bin/perl" =~ m"/perl"
>>
>> I can just write
>>
>> "/usr/bin/perl" =~ "/perl"
>>
>> Can anyone point me to the documentation indicating which delimiters
>> don't need the 'm' operator?
>>
>>
>> you actually are thinking in the wrong direction. the =~ operator causes
>> its right side to always be a regex unless the s/// or m// or tr/// ops are
>> seen there. you can even use an expression or sub call or anything on the
>> right of =~ and it will be parsed as a regex (if no op is there as i just
>> said).
>>
>> you can easily check this out with something simple like "/usr/bin/perl"
>> =~ "/pe" . "rl".
>>
>> so it isn't the delimiters as you think but the =~ op itself that makes
>> it a regex.
>>
>> uri
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>
>>
>>
>> --
>> Andrew Solomon
>>
>> Mentor@Geekuni http://geekuni.com/
>> http://www.linkedin.com/in/asolomon
>>
>


-- 
Andrew Solomon

Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon


Re: interesting regex delimiters

2017-02-24 Thread Chas. Owens
Be careful, it isn't actually a regex; it is a string that will be compiled
to a regex.  You can see one difference here:

#!/usr/bin/perl

use v5.20;
use warnings;

say "string matches:";
for my $s ("foo", "AfooZ") {
say "\t$s: ", $s =~ "\Afoo\Z" ? "true" : "false";
}

say "regex matches:";
for my $s ("foo", "AfooZ") {
say "\t$s: ", $s =~ /\Afoo\Z/ ? "true" : "false";
}

which outputs

Unrecognized escape \A passed through at t.pl line 8.
Unrecognized escape \Z passed through at t.pl line 8.
string matches:
foo: false
AfooZ: true
regex matches:
foo: true
AfooZ: false

To my knowledge, the only delimiters that do not require m or qr before
them are // and ??; however, they are not equivalent (and ?? must be m?? as
of Perl 5.22).  The m?? operator only matches the first time it sees a
pattern and then will not match again until reset is called:

#!/usr/bin/perl

use v5.18;
use warnings;

for ("fo", "foo", "fooo", "f") {
my ($match) = ?(fo+)?;
say $match // "no match";
if (/fooo/) {
reset;
}
}

Which outputs

Use of ?PATTERN? without explicit operator is deprecated at t.pl line 7.
fo
no match
no match
f


On Thu, Feb 23, 2017 at 6:53 PM Andrew Solomon <and...@geekuni.com> wrote:

> Thanks Uri!
>
> On Thu, Feb 23, 2017 at 10:32 PM, Uri Guttman <u...@stemsystems.com> wrote:
>
> On 02/23/2017 05:19 PM, Andrew Solomon wrote:
>
> Running Perl 18.2 I was surprised to discover that I can use single and
> double quotes as regex delimiters without the 'm' operator.
>
> For example, instead of writing
>
> "/usr/bin/perl" =~ m"/perl"
>
> I can just write
>
> "/usr/bin/perl" =~ "/perl"
>
> Can anyone point me to the documentation indicating which delimiters don't
> need the 'm' operator?
>
>
> you actually are thinking in the wrong direction. the =~ operator causes
> its right side to always be a regex unless the s/// or m// or tr/// ops are
> seen there. you can even use an expression or sub call or anything on the
> right of =~ and it will be parsed as a regex (if no op is there as i just
> said).
>
> you can easily check this out with something simple like "/usr/bin/perl"
> =~ "/pe" . "rl".
>
> so it isn't the delimiters as you think but the =~ op itself that makes it
> a regex.
>
> uri
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>
>
>
> --
> Andrew Solomon
>
> Mentor@Geekuni http://geekuni.com/
> http://www.linkedin.com/in/asolomon
>


Re: interesting regex delimiters

2017-02-23 Thread Andrew Solomon
Thanks Uri!

On Thu, Feb 23, 2017 at 10:32 PM, Uri Guttman <u...@stemsystems.com> wrote:

> On 02/23/2017 05:19 PM, Andrew Solomon wrote:
>
>> Running Perl 18.2 I was surprised to discover that I can use single and
>> double quotes as regex delimiters without the 'm' operator.
>>
>> For example, instead of writing
>>
>> "/usr/bin/perl" =~ m"/perl"
>>
>> I can just write
>>
>> "/usr/bin/perl" =~ "/perl"
>>
>> Can anyone point me to the documentation indicating which delimiters
>> don't need the 'm' operator?
>>
>>
>> you actually are thinking in the wrong direction. the =~ operator causes
> its right side to always be a regex unless the s/// or m// or tr/// ops are
> seen there. you can even use an expression or sub call or anything on the
> right of =~ and it will be parsed as a regex (if no op is there as i just
> said).
>
> you can easily check this out with something simple like "/usr/bin/perl"
> =~ "/pe" . "rl".
>
> so it isn't the delimiters as you think but the =~ op itself that makes it
> a regex.
>
> uri
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
Andrew Solomon

Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon


Re: interesting regex delimiters

2017-02-23 Thread Uri Guttman

On 02/23/2017 05:19 PM, Andrew Solomon wrote:
Running Perl 18.2 I was surprised to discover that I can use single 
and double quotes as regex delimiters without the 'm' operator.


For example, instead of writing

"/usr/bin/perl" =~ m"/perl"

I can just write

"/usr/bin/perl" =~ "/perl"

Can anyone point me to the documentation indicating which delimiters 
don't need the 'm' operator?



you actually are thinking in the wrong direction. the =~ operator causes 
its right side to always be a regex unless the s/// or m// or tr/// ops 
are seen there. you can even use an expression or sub call or anything 
on the right of =~ and it will be parsed as a regex (if no op is there 
as i just said).


you can easily check this out with something simple like "/usr/bin/perl" 
=~ "/pe" . "rl".


so it isn't the delimiters as you think but the =~ op itself that makes 
it a regex.


uri

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




interesting regex delimiters

2017-02-23 Thread Andrew Solomon
Running Perl 18.2 I was surprised to discover that I can use single and
double quotes as regex delimiters without the 'm' operator.

For example, instead of writing

"/usr/bin/perl" =~ m"/perl"

I can just write

"/usr/bin/perl" =~ "/perl"

Can anyone point me to the documentation indicating which delimiters don't
need the 'm' operator?

Thanks

Andrew


Re: Regex for matching files that don't have type extensions

2016-11-05 Thread Shawn H Corey
On Sat, 05 Nov 2016 21:30:12 +
Aaron Wells  wrote:

> True. It could get hairy. Unicode is a pretty vast landscape, and I
> think if you only want ASCII word characters to count as things that
> could be in a filename, your original [A-Za-z0-9_] is your best bet.
> Thanks to the others for their comments. As Ken says: there are
> probably more ways to code this.

TIMTOWTDI
https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it

;)

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex for matching files that don't have type extensions

2016-11-05 Thread Octavian Rasnita
From: Aaron Wells 


  True. It could get hairy. Unicode is a pretty vast landscape, and I think if 
you only want ASCII word characters to count as things that could be in a 
filename, your original [A-Za-z0-9_] is your best bet. Thanks to the others for 
their comments. As Ken says: there are probably more ways to code this.




Another (shorter) way of writing that can be:

/^\w+$/aa

Where /aa makes \w mean just [A-Za-z0-9_].

a = ASCII and aa is used for double protection, so only ASCII is used.

--Octavian



Re: Regex for matching files that don't have type extensions

2016-11-05 Thread X Dungeness
On Sat, Nov 5, 2016 at 10:55 AM, Jovan Trujillo
 wrote:
> Hi Aaron,
>In perlre I read that \w
> "
>
> \w[3]  Match a "word" character (alphanumeric plus "_", plus
>   other connector punctuation chars plus
> Unicode
>   marks)
>
> "
>
> So since I didn't know what these 'other' connection punctuation chars are I
> avoided it. Unicode makes things more complicated for me. Do you know?
>

To exclude Unicode and ensure only ASCII, use the /a modifer,
eg,  /\w+/a

>From perlre:

/a

   is the same as "/u", except that "\d", "\s", "\w", and the Posix
   character classes are restricted to matching in the ASCII range only.
   That is, with this modifier, "\d" always means precisely the digits "0"
   to "9"; "\s" means the five characters "[ \f\n\r\t]"; "\w" means the 63
   characters "[A-Za-z0-9_]"; and likewise, all the Posix classes such as
   "[[:print:]]" match only the appropriate ASCII-range characters.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




  1   2   3   4   5   6   7   8   9   10   >