reg exp help
-- Hi, The content of file hello.c is as given below. I want to count how many + and - are there in this file. I had equivalent shel command to count no. of + and -, grep -e ^+[^+] diffs.txt | wc -l grep -e ^-[^-] diffs.txt | wc -l Can anyone help me how to write perl script using regular expression which should count no. of + and -. +++ hello.c 8 Mar 2006 13:55:13 - 1.9 @@ -1,16 +1,19 @@ +func() +{ + print(eep Si\n; +printf(This line has been added after first commit by sandeep); +printf(Hi iam last time committing); +printf(Hi iam inserting some change in the code.); +} -Hi ther i have been here - -hi ther good one - -Hi iam last time committing - -jkdklsf asdf Thank you Regards Sandeep -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
On 4/27/06, sandy [EMAIL PROTECTED] wrote: Hi, The content of file hello.c is as given below. I want to count how many + and - are there in this file. I had equivalent shel command to count no. of + and -, grep -e ^+[^+] diffs.txt | wc -l grep -e ^-[^-] diffs.txt | wc -l You say two different things here. Your email sayas you want to count the number of '+' and '-', but your grep command count the number lof lines that start with a single '+' or '-'. Those are two very differnt things. Can anyone help me how to write perl script using regular expression which should count no. of + and -. [snip] The simplest would probably be something like: my ($plus, $minus); while () { $plus++, next if /^\+[^+]/; $minus++ if /^-[^-]/; } See perlretut for more. HTH, --jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!
reg exp help
Can anyone help me with this match: #!/usr/bin/perl use strict; use warnings; my $talxkeylog =qq(/home/gpghrp/.gnupg/keys/log/talxkeyupd.log); open (FH, +$talxkeylog) or warn unable to open file $talxkeylog $! ; #cURL(); #print $calcdate\n$curtdate; my ($lc,$lcc) =$.; ($lc,$lcc) =0; if ( 2 == 2 ) { #print FH Time for TALX public key update!\t\n; #print FH $calcdate\n$curtdate; #cURL(); for (;FH;) { if (/^-{5,}(\w+)/ig) { print $_; } $lc++; } } close (FH); thanks I want to print everything from BEGIN TO END and right now all I am printing is the begin and end lines. __END_CODE__ __BEGIN _DATA__ -BEGIN PGP PUBLIC KEY BLOCK- Version: PGP 6.5 mQGiBEJIFiERBAD3c5VkK6sD5+ngCpeRazBdKR416ePaC6irWnIigw7m97W+U+u3 Vuts/+22VxMi+KrXkCn2lq7UcOaeIANN1oDrku2yeJR1rRjwu5+pE5e+kh6rSkuP Lk3pheiLg/WwC/jqJPsYaPnJ2brC8EVVFi/LFOKtBbkII4wuYJJukZbZtwCg/2ZT 9rvvLane4MwbVfufX/9hBz0D/j8Z+zyWEmLs/bd+l+1NKq2+pHz6K+pVhYfG3hAf 1y7krPWfniXGsrxIDV7rZqKDAyuxhfksGfMWYKLjHfN7Xm8RbGMJJF1NTx8VwhNO imykmCyYYac+/Dh0C7WmGEOPhlIoG8pTjY/xc7ZoEWpbmHDTXqQA+ztJ6JeXJIEz OIb0BADP1uozyE1DnRUsW8PUIqCtrcel91qD8PtC7aqmoSkAZ2uVHHRxCp3aGXZV lc+yuwaK0L7WC9+/+OwAVioeeK3O5rOx9/IDA52Hvy1v5jVNcqODfdck6tc4fLkV GuIMoVs2AiU/6PJp2VVkYu7zZAFGM9NZBEw26TqsNR7qj+t0urQfdGFseGNvcnAx MTE2MjAwNSA8cGdwQHRhbHguY29tPokAUwQQEQIAFAUCQkgWIQUJATMtgAQLAwIB AhkBAAoJEPRUp2yIbsWrN60Al0I67BjENfAvX0tkcL6FyZMnq5cAnRkO8yuXR1ac mY8ivrh6eB2xcrPquQINBEJIFiEQCAD2Qle3CH8IF3KiutapQvMF6PlTETlPtvFu uUs4INoBp1ajFOmPQFXz0AfGy0OplK33TGSGSfgMg71l6RfUodNQ+PVZX9x2Uk89 PY3bzpnhV5JZzf24rnRPxfx2vIPFRzBhznzJZv8V+bv9kV7HAarTW56NoKVyOtQa 8L9GAFgr5fSI/VhOSdvNILSd5JEHNmszbDgNRR0PfIizHHxbLY7288kjwEPwpVsY jY67VYy4XTjTNP18F1dDox0YbN4zISy1Kv884bEpQBgRjXyEpwpy1obEAxnIByl6 ypUM2Zafq9AKUJsCRtMIPWakXUGfnHy9iUsiGSa6q6Jew1XpMgs7AAICCACba3FM XQz1awim/Qv1+AAPyGeVqjNwBzBHckbbn5ck6ZYEJ9V29FxqB9iKk68vS/Qwc+XJ g9JUaxyS2f9d88qHISBeHJ+/9a7LXghexO2AraDD8IFGv88zDc9nMsPlh0EXZCTV SUegpEQB6tuTEYe5B0WOVt2ZIDvHnVkxnZgycwQ0r2Dw2amvkATgoD6IBKGk/WMO qNrK/zcslGScfNbj5ExQ2az/32tHX/Exuys0Z2ahwkiWj6d0ggKUIFdcnm/m3egd f9eiGvoHPPLhnFszDt3Dbw2MP6Yorr2l5vJ2VktCpAO3teSKAVNt++UKpb/0Ykik PhRRq0DyPQ5xlShYiQBMBBgRAgAMBQJCSBYhBQkBMy2AAAoJEPRUp2yIbsWr8Q0A niD9KAivhqxjhohFPrSWqNYqfRkRAKClRpDGTcVc4WIZQFDjfaACXqJUiA== =/2pu -END PGP PUBLIC KEY BLOCK- Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
Hello, First of all you're opening the file for writing Second i didn't understand what you really want , if you want to print out everything inside the file my $file = 'newfile.txt'; open(FILE,$file); while(FILE){ print $_;} close(FILE); That's it with out matching or anything bye On 6/28/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Can anyone help me with this match: #!/usr/bin/perl use strict; use warnings; my $talxkeylog =qq(/home/gpghrp/.gnupg/keys/log/talxkeyupd.log); open (FH, +$talxkeylog) or warn unable to open file $talxkeylog $! ; #cURL(); #print $calcdate\n$curtdate; my ($lc,$lcc) =$.; ($lc,$lcc) =0; if ( 2 == 2 ) { #print FH Time for TALX public key update!\t\n; #print FH $calcdate\n$curtdate; #cURL(); for (;FH;) { if (/^-{5,}(\w+)/ig) { print $_; } $lc++; } } close (FH); thanks I want to print everything from BEGIN TO END and right now all I am printing is the begin and end lines. __END_CODE__ __BEGIN _DATA__ -BEGIN PGP PUBLIC KEY BLOCK- Version: PGP 6.5 mQGiBEJIFiERBAD3c5VkK6sD5+ngCpeRazBdKR416ePaC6irWnIigw7m97W+U+u3 Vuts/+22VxMi+KrXkCn2lq7UcOaeIANN1oDrku2yeJR1rRjwu5+pE5e+kh6rSkuP Lk3pheiLg/WwC/jqJPsYaPnJ2brC8EVVFi/LFOKtBbkII4wuYJJukZbZtwCg/2ZT 9rvvLane4MwbVfufX/9hBz0D/j8Z+zyWEmLs/bd+l+1NKq2+pHz6K+pVhYfG3hAf 1y7krPWfniXGsrxIDV7rZqKDAyuxhfksGfMWYKLjHfN7Xm8RbGMJJF1NTx8VwhNO imykmCyYYac+/Dh0C7WmGEOPhlIoG8pTjY/xc7ZoEWpbmHDTXqQA+ztJ6JeXJIEz OIb0BADP1uozyE1DnRUsW8PUIqCtrcel91qD8PtC7aqmoSkAZ2uVHHRxCp3aGXZV lc+yuwaK0L7WC9+/+OwAVioeeK3O5rOx9/IDA52Hvy1v5jVNcqODfdck6tc4fLkV GuIMoVs2AiU/6PJp2VVkYu7zZAFGM9NZBEw26TqsNR7qj+t0urQfdGFseGNvcnAx MTE2MjAwNSA8cGdwQHRhbHguY29tPokAUwQQEQIAFAUCQkgWIQUJATMtgAQLAwIB AhkBAAoJEPRUp2yIbsWrN60Al0I67BjENfAvX0tkcL6FyZMnq5cAnRkO8yuXR1ac mY8ivrh6eB2xcrPquQINBEJIFiEQCAD2Qle3CH8IF3KiutapQvMF6PlTETlPtvFu uUs4INoBp1ajFOmPQFXz0AfGy0OplK33TGSGSfgMg71l6RfUodNQ+PVZX9x2Uk89 PY3bzpnhV5JZzf24rnRPxfx2vIPFRzBhznzJZv8V+bv9kV7HAarTW56NoKVyOtQa 8L9GAFgr5fSI/VhOSdvNILSd5JEHNmszbDgNRR0PfIizHHxbLY7288kjwEPwpVsY jY67VYy4XTjTNP18F1dDox0YbN4zISy1Kv884bEpQBgRjXyEpwpy1obEAxnIByl6 ypUM2Zafq9AKUJsCRtMIPWakXUGfnHy9iUsiGSa6q6Jew1XpMgs7AAICCACba3FM XQz1awim/Qv1+AAPyGeVqjNwBzBHckbbn5ck6ZYEJ9V29FxqB9iKk68vS/Qwc+XJ g9JUaxyS2f9d88qHISBeHJ+/9a7LXghexO2AraDD8IFGv88zDc9nMsPlh0EXZCTV SUegpEQB6tuTEYe5B0WOVt2ZIDvHnVkxnZgycwQ0r2Dw2amvkATgoD6IBKGk/WMO qNrK/zcslGScfNbj5ExQ2az/32tHX/Exuys0Z2ahwkiWj6d0ggKUIFdcnm/m3egd f9eiGvoHPPLhnFszDt3Dbw2MP6Yorr2l5vJ2VktCpAO3teSKAVNt++UKpb/0Ykik PhRRq0DyPQ5xlShYiQBMBBgRAgAMBQJCSBYhBQkBMy2AAAoJEPRUp2yIbsWr8Q0A niD9KAivhqxjhohFPrSWqNYqfRkRAKClRpDGTcVc4WIZQFDjfaACXqJUiA== =/2pu -END PGP PUBLIC KEY BLOCK- Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
Actually, you are incorrect... The + mean read and write in append mode. Please see the follow up email with the attachment I sent. Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 bright true [EMAIL PROTECTED] .com To [EMAIL PROTECTED] 06/28/2005 10:45 [EMAIL PROTECTED] AM cc beginners@perl.org Subject Please respond to Re: reg exp help bright true [EMAIL PROTECTED] .com Hello, First of all you're opening the file for writing Second i didn't understand what you really want , if you want to print out everything inside the file my $file = 'newfile.txt'; open(FILE,$file); while(FILE){ print $_;} close(FILE); That's it with out matching or anything bye On 6/28/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Can anyone help me with this match: #!/usr/bin/perl use strict; use warnings; my $talxkeylog =qq(/home/gpghrp/.gnupg/keys/log/talxkeyupd.log); open (FH, +$talxkeylog) or warn unable to open file $talxkeylog $! ; #cURL(); #print $calcdate\n$curtdate; my ($lc,$lcc) =$.; ($lc,$lcc) =0; if ( 2 == 2 ) { #print FH Time for TALX public key update!\t\n; #print FH $calcdate\n$curtdate; #cURL(); for (;FH;) { if (/^-{5,}(\w+)/ig) { print $_; } $lc++; } } close (FH); thanks I want to print everything from BEGIN TO END and right now all I am printing is the begin and end lines. __END_CODE__ __BEGIN _DATA__ -BEGIN PGP PUBLIC KEY BLOCK- Version: PGP 6.5 mQGiBEJIFiERBAD3c5VkK6sD5+ngCpeRazBdKR416ePaC6irWnIigw7m97W+U+u3 Vuts/+22VxMi+KrXkCn2lq7UcOaeIANN1oDrku2yeJR1rRjwu5+pE5e+kh6rSkuP Lk3pheiLg/WwC/jqJPsYaPnJ2brC8EVVFi/LFOKtBbkII4wuYJJukZbZtwCg/2ZT 9rvvLane4MwbVfufX/9hBz0D/j8Z+zyWEmLs/bd+l+1NKq2+pHz6K+pVhYfG3hAf 1y7krPWfniXGsrxIDV7rZqKDAyuxhfksGfMWYKLjHfN7Xm8RbGMJJF1NTx8VwhNO imykmCyYYac+/Dh0C7WmGEOPhlIoG8pTjY/xc7ZoEWpbmHDTXqQA+ztJ6JeXJIEz OIb0BADP1uozyE1DnRUsW8PUIqCtrcel91qD8PtC7aqmoSkAZ2uVHHRxCp3aGXZV lc+yuwaK0L7WC9+/+OwAVioeeK3O5rOx9/IDA52Hvy1v5jVNcqODfdck6tc4fLkV GuIMoVs2AiU/6PJp2VVkYu7zZAFGM9NZBEw26TqsNR7qj+t0urQfdGFseGNvcnAx MTE2MjAwNSA8cGdwQHRhbHguY29tPokAUwQQEQIAFAUCQkgWIQUJATMtgAQLAwIB AhkBAAoJEPRUp2yIbsWrN60Al0I67BjENfAvX0tkcL6FyZMnq5cAnRkO8yuXR1ac mY8ivrh6eB2xcrPquQINBEJIFiEQCAD2Qle3CH8IF3KiutapQvMF6PlTETlPtvFu uUs4INoBp1ajFOmPQFXz0AfGy0OplK33TGSGSfgMg71l6RfUodNQ+PVZX9x2Uk89 PY3bzpnhV5JZzf24rnRPxfx2vIPFRzBhznzJZv8V+bv9kV7HAarTW56NoKVyOtQa 8L9GAFgr5fSI/VhOSdvNILSd5JEHNmszbDgNRR0PfIizHHxbLY7288kjwEPwpVsY jY67VYy4XTjTNP18F1dDox0YbN4zISy1Kv884bEpQBgRjXyEpwpy1obEAxnIByl6 ypUM2Zafq9AKUJsCRtMIPWakXUGfnHy9iUsiGSa6q6Jew1XpMgs7AAICCACba3FM XQz1awim/Qv1+AAPyGeVqjNwBzBHckbbn5ck6ZYEJ9V29FxqB9iKk68vS/Qwc+XJ g9JUaxyS2f9d88qHISBeHJ+/9a7LXghexO2AraDD8IFGv88zDc9nMsPlh0EXZCTV SUegpEQB6tuTEYe5B0WOVt2ZIDvHnVkxnZgycwQ0r2Dw2amvkATgoD6IBKGk/WMO qNrK/zcslGScfNbj5ExQ2az/32tHX/Exuys0Z2ahwkiWj6d0ggKUIFdcnm/m3egd f9eiGvoHPPLhnFszDt3Dbw2MP6Yorr2l5vJ2VktCpAO3teSKAVNt++UKpb/0Ykik PhRRq0DyPQ5xlShYiQBMBBgRAgAMBQJCSBYhBQkBMy2AAAoJEPRUp2yIbsWr8Q0A niD9KAivhqxjhohFPrSWqNYqfRkRAKClRpDGTcVc4WIZQFDjfaACXqJUiA== =/2pu -END PGP PUBLIC KEY BLOCK- Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
On 6/28/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Can anyone help me with this match: [snip] for (;FH;) { if (/^-{5,}(\w+)/ig) { print $_; } $lc++; } [snip] This says if the line matches five dashes and at least one word character (which you are capturing for some reason), then print the line. What you want is the exact opposite: while (FH) { print $_ unless /^-{5,}/ ; } And use while instead of the awkward for (;;) construction; this is what it's there for. -- jay daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
On Jun 28, [EMAIL PROTECTED] said: for (;FH;) { if (/^-{5,}(\w+)/ig) { print $_; } $lc++; } I want to print everything from BEGIN TO END and right now all I am printing is the begin and end lines. If that's what you want, you should use two regexes with the .. operator: while (FH) { # this is better-looking than 'for (;FH;)' if (/^-BEGIN/ .. /^-END/) { print; } } The flip-flop operator (..) is *false* UNTIL the left expression evaluates to true. THEN it STAYS *true* until the right expression evaluates to true. -- Jeff japhy Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ %-- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
On 6/28/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Actually, you are incorrect... The + mean read and write in append mode. Please see the follow up email with the attachment I sent. Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 While you are correct, please don't do this. It's a great way to get yourself into trouble and really only serves to obfuscate your code and ensure that filehandles remain open when they aren't being used, eating up kernel resources. When you need to read from a file, open it, read from it, and close it. then when you're ready to write to it, open it, write to it, and close it. If you really insist on obsfucation (using for (;;) and using your own variable when $. or $.-1 would suffice indicate you might) make sure you use appropriate select() calls to make sure you're not getting premature EOF, and depending on your OS, also when switching from reading to writing, and vice versa. But really, the perl philosphy is to keep the simple things simple. And reading a file, printing a few lines you want, and closing the file is about as simple as it gets. in fact, it's a one-liner: perl -lne 'print unless /^-{5}/' your_file -- jay daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
On Jun 28, [EMAIL PROTECTED] said: but here is another piece of code I tried and this worked as well considering the attachment: comments on the below block? [snip] if (m/begin pgp public key block/ig) { $lc=1; } if ( $lc==1){ print $_; } if (m/end pgp public key block/ig) { $lc=0; } What comment do you want? This is 100% identical to using a flip-flop, except that you have an explicit variable holding the truth value. It starts as false. If the first regex matches, then $lc is true. If $lc is true, print the current line. If the second regex matches, then $lc is false. Identical. Use a flip-flop. It's easier. -- Jeff japhy Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ %-- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
On 6/28/05, Jeff 'japhy' Pinyan [EMAIL PROTECTED] wrote: On Jun 28, [EMAIL PROTECTED] said: but here is another piece of code I tried and this worked as well considering the attachment: comments on the below block? [snip] if (m/begin pgp public key block/ig) { $lc=1; } if ( $lc==1){ print $_; } if (m/end pgp public key block/ig) { $lc=0; } What comment do you want? This is 100% identical to using a flip-flop, except that you have an explicit variable holding the truth value. It starts as false. If the first regex matches, then $lc is true. If $lc is true, print the current line. If the second regex matches, then $lc is false. Identical. Use a flip-flop. It's easier. -- Not quite. In this code, $lc is not set to zero until after the test for $lc == 1, so the -END.+ line will be printed. A flip-flop on the other hand--which you have now recommended at least twice--does exactly what he's looking for. -- jay daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp help
On 6/28/05, Jay Savage [EMAIL PROTECTED] wrote: On 6/28/05, Jeff 'japhy' Pinyan [EMAIL PROTECTED] wrote: On Jun 28, [EMAIL PROTECTED] said: but here is another piece of code I tried and this worked as well considering the attachment: comments on the below block? [snip] if (m/begin pgp public key block/ig) { $lc=1; } if ( $lc==1){ print $_; } if (m/end pgp public key block/ig) { $lc=0; } What comment do you want? This is 100% identical to using a flip-flop, except that you have an explicit variable holding the truth value. It starts as false. If the first regex matches, then $lc is true. If $lc is true, print the current line. If the second regex matches, then $lc is false. Identical. Use a flip-flop. It's easier. -- Not quite. In this code, $lc is not set to zero until after the test for $lc == 1, so the -END.+ line will be printed. A flip-flop on the other hand--which you have now recommended at least twice--does exactly what he's looking for. -- jay I'm sorry, I read too fast. I thought in the original code the begin was supressed. You are absolutely correct. The consecutive ifs yeild exactly the same result as the flipflop. I hit send too hastily. -- jay daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reg Exp Help
Hi If Request timed out occurs in the output from PING command you can be quite sure that the request timed out. :-) Therefore it's be bit to much hazzle to check for embedded newlines (using the \m modifier), one could just say: if ($machine_status =~ /Request timed out\./) { Remember to escape the period (.), it has a speciel meaning in regex (can be any charachter more or less) Maybe you should also consider using Net::Ping instead of using a system call to the PING command! At least I hope you are checking the return code from the system call. ;-) Gretar Mar Trina Espinoza wrote: Var $machine_status contains this block of data: machine_status = Pinging 129.111.3.79 with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. Ping statistics for 192.111.3.79: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms I am trying to do a regular expression to see if the block contains the string Request timed out. from the block. My regular expression is below, but it fails to find the string Request timed out. What am I doing wrong? if ($machine_status =~ /^Request timed out.$/m) { Any help appreciated, -T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Reg Exp Help
Var $machine_status contains this block of data: machine_status = Pinging 129.111.3.79 with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. Ping statistics for 192.111.3.79: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms I am trying to do a regular expression to see if the block contains the string Request timed out. from the block. My regular expression is below, but it fails to find the string Request timed out. What am I doing wrong? if ($machine_status =~ /^Request timed out.$/m) { Any help appreciated, -T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reg Exp Help
Trina Espinoza wrote: Var $machine_status contains this block of data: machine_status = Pinging 129.111.3.79 with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. Ping statistics for 192.111.3.79: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms I am trying to do a regular expression to see if the block contains the string Request timed out. from the block. My regular expression is below, but it fails to find the string Request timed out. What am I doing wrong? if ($machine_status =~ /^Request timed out.$/m) { It looks like there are spaces at the end of those lines. Also the . character is special in regular expressions so you have to escape it. if ($machine_status =~ /^Request timed out\. *$/m) { John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Reg Exp Help...
I know that this is a common request, but I have a question about parsing an email box. I have a UW IMAP box, and I am trying to extract all the emails where the line starts with From: blah blah. Now, getting those lines isn't the issue, but since each email is a little different, I am having a problem. Given this list, how would I extract JUST the email address? From: James Kelty [EMAIL PROTECTED] From: [EMAIL PROTECTED] From: [EMAIL PROTECTED] There are three types that I have seen, and I am having the worst time trying to come up with a regex to extract just the address. Can someone help with an idea or two? Thanks! -James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reg Exp Help...
On 22 Jul 2003 09:15:29 -0700, James Kelty [EMAIL PROTECTED] wrote: I know that this is a common request, but I have a question about parsing an email box. I have a UW IMAP box, and I am trying to extract all the emails where the line starts with From: blah blah. Now, getting those lines isn't the issue, but since each email is a little different, I am having a problem. Given this list, how would I extract JUST the email address? From: James Kelty [EMAIL PROTECTED] From: [EMAIL PROTECTED] From: [EMAIL PROTECTED] There are three types that I have seen, and I am having the worst time trying to come up with a regex to extract just the address. Can someone help with an idea or two? Thanks! This is a relatively complex task since e-mail addresses can come in so many different forms and contain so many different types of values. Your best bet may be to either use a module for parsing the whole message which is always advised, or look at the source for one of the better message header parsing modules to determine how they are doing it. Sorry this is such a non-specific answer, but rather than suggesting a way to poorly re-invent the wheel, I prefer suggesting that this should be avoided http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reg Exp Help...
- Original Message - From: [EMAIL PROTECTED] To: James Kelty [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 23, 2003 1:21 AM Subject: RE: Reg Exp Help... On 22 Jul 2003 09:15:29 -0700, James Kelty [EMAIL PROTECTED] wrote: I know that this is a common request, but I have a question about parsing an email box. I have a UW IMAP box, and I am trying to extract all the emails where the line starts with From: blah blah. Now, getting those lines isn't the issue, but since each email is a little different, I am having a problem. Given this list, how would I extract JUST the email address? From: James Kelty [EMAIL PROTECTED] From: [EMAIL PROTECTED] From: [EMAIL PROTECTED] snipped This is a relatively complex task since e-mail addresses can come in so many different forms and contain so many different types of values. Your best bet may be to either use a module for parsing the whole message which is always advised, or look at the source for one of the better message header parsing modules to determine how they are doing it. Sorry this is such a non-specific answer, but rather than suggesting a way to poorly re-invent the wheel, I prefer suggesting that this should be avoided Hmm The OP seems not trying to do somewhat Email::Valid, but to fetch the mail address from a line only... ie, try to cut out something not expect to left... I hope I bet it correct.. sub filter {my $line = shift; chomp ($line); chop ($line) if ($line =~ /[^\w]$/; # mail must end with tld or country code my ($waste, $mailAd) = split / /, $line ; # So 'From: ' is kicked out $mailAd =~ s/^[^\w]//; # so '' or '' will be kicked out from head too... # Perhaps the regex above can be [^\w|\\] if [EMAIL PROTECTED] is valid # I am not sure return $mailAd } Code not tested, but HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reg Exp Help...
James Kelty wrote: I know that this is a common request, but I have a question about parsing an email box. I have a UW IMAP box, and I am trying to extract all the emails where the line starts with From: blah blah. Now, getting those lines isn't the issue, but since each email is a little different, I am having a problem. Given this list, how would I extract JUST the email address? From: James Kelty [EMAIL PROTECTED] From: [EMAIL PROTECTED] From: [EMAIL PROTECTED] There are three types that I have seen, and I am having the worst time trying to come up with a regex to extract just the address. Can someone help with an idea or two? Thanks! It looks like you could use one of these modules: http://search.cpan.org/author/MARKOV/MailTools-1.58/Mail/Address.pm http://search.cpan.org/author/PDWARREN/Mail-RFC822-Address-0.3/Address.pm http://search.cpan.org/author/ABIGAIL/RFC_RFC822_Address-1.5/Address.pm John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reg Exp Help...
On Wed, 23 Jul 2003 02:41:28 +0800, LI NGOK LAM [EMAIL PROTECTED] wrote: - Original Message - From: [EMAIL PROTECTED] To: James Kelty [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 23, 2003 1:21 AM Subject: RE: Reg Exp Help... On 22 Jul 2003 09:15:29 -0700, James Kelty [EMAIL PROTECTED] wrote: I know that this is a common request, but I have a question about parsing an email box. I have a UW IMAP box, and I am trying to extract all the emails where the line starts with From: blah blah. Now, getting those lines isn't the issue, but since each email is a little different, I am having a problem. Given this list, how would I extract JUST the email address? From: James Kelty [EMAIL PROTECTED] From: [EMAIL PROTECTED] From: [EMAIL PROTECTED] snipped This is a relatively complex task since e-mail addresses can come in so many different forms and contain so many different types of values. Your best bet may be to either use a module for parsing the whole message which is always advised, or look at the source for one of the better message header parsing modules to determine how they are doing it. Sorry this is such a non-specific answer, but rather than suggesting a way to poorly re-invent the wheel, I prefer suggesting that this should be avoided Hmm The OP seems not trying to do somewhat Email::Valid, but to fetch the mail address from a line only... ie, try to cut out something not expect to left... I hope I bet it correct.. sub filter {my $line = shift; chomp ($line); chop ($line) if ($line =~ /[^\w]$/; # mail must end with tld or country code my ($waste, $mailAd) = split / /, $line ; # So 'From: ' is kicked out $mailAd =~ s/^[^\w]//; # so '' or '' will be kicked out from head too... # Perhaps the regex above can be [^\w|\\] if [EMAIL PROTECTED] is valid # I am not sure return $mailAd } Code not tested, but HTH Thank you for illustrating my point. I understood that the OP was not trying to verify the validity of an address but to retrieve it, but your code snippet fails on the OPs first line of data, which was my point, parsing email addresses out of a line of data is a very difficult task that is easily botched. (There is also a missing right paren for those that get caught by the syntax check.) A true e-mail address is an incredibly complex and nasty little beast, so matching them while it may seem simple at first becomes a nightmare quickly. Possibly the OP would be satisfied with just stripping off the 'From:' if that is guaranteed... if ($line =~ /^From:\s*(.*)/) { $address = $1; } else { die Not a 'From' line; } I still hold that this is best handled by a module that is designed to parse a mail message, or at the very least a module designed to parse either a message header, or a single header line that contains e-mail addresses. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SV: reg exp help!
Hi, This should work. $_ = $your_string_array; $_ =~ /accessed (.*?)\./; $date = $1; print $date; Regards, Mikael Larsson -Ursprungligt meddelande- Från: David Samuelsson (PAC) [mailto:[EMAIL PROTECTED]] Skickat: den 26 mars 2002 11:53 Till: '[EMAIL PROTECTED]' Ämne: reg exp help! i got this line in an array allready, if i do a print off the array it prints this line. Last accessed 08-mar-02.10:27:55 by fdefgre.Domain [EMAIL PROTECTED] what i want to do now is only pick out the date that is the 08-mar-02 As it says in the manuals, one of the best with things with perl is the abillity to use regexp, but also one of the worst/hardest things aswell =) //Dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: reg exp help!
From: David Samuelsson (PAC) [EMAIL PROTECTED] i got this line in an array allready, if i do a print off the array it prints this line. Last accessed 08-mar-02.10:27:55 by fdefgre.Domain [EMAIL PROTECTED] what i want to do now is only pick out the date that is the 08-mar-02 As it says in the manuals, one of the best with things with perl is the abillity to use regexp, but also one of the worst/hardest things aswell =) I't impossible to create a proper regexp for you if we do not know how do ALL the rows you are interested in look like. If I assume all start with Last accessed I would suggest: $line =~ /^Last accessed (\d{1,2}-\w+-\d{1,2})/ and $date = $1; if you want to look up dates in this format in any lines: $line =~ /(\d{1,2}-\w+-\d{1,2})/ and $date = $1; actually since your dates seem to contain the leading zeroes you could use \d\d- a cipher followed by another cipher or \d{2} - two ciphers instead of \d{1,2} - one or two ciphers Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reg Exp help
Thanks Daryl 'Japhy' for your suggestions. I ended up using: $Out = `$Cmd` ; $Out =~ /^\|GRP\|\s*(.*)/m ; The data I want ends up in $1. -Original Message- From: Busse, Rich Sent: Tuesday, 26 February, 2002 09:35 To: Perl Beginners Subject: Reg Exp help I am capturing the output of a command in a string: $Out = `$Cmd` ; The output always looks like: List of Templates and Template Groups assigned to 'somenode.us.dnb.com': |GRP| SBS-DSM Operation successfully completed. It's always on 5 separate lines. How do I extract what follows |GRP| on the third line to a variable? TIA... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Reg Exp help
I am capturing the output of a command in a string: $Out = `$Cmd` ; The output always looks like: List of Templates and Template Groups assigned to 'somenode.us.dnb.com': |GRP| SBS-DSM Operation successfully completed. It's always on 5 separate lines. How do I extract what follows |GRP| on the third line to a variable? TIA... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reg Exp help
If there is only one of the lines |GRP| this will work. Otherwise I would push the lines into a an array instead of a variable. @Out = `$Cmd`; $WhatFollowsGRP = ; foreach my $line (@Out) { if($line =~ /|GRP|/) { $line =~ s/|GRP|//; $WhatFollowsGRP = $line; }# end if }# end foreach loop Daryl J. Hoyt Performance Engineer Geodesic Systems 312-832-2010 http://www.geodesic.com mailto:[EMAIL PROTECTED] -Original Message- From: Busse, Rich [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 26, 2002 8:35 AM To: Perl Beginners Subject: Reg Exp help I am capturing the output of a command in a string: $Out = `$Cmd` ; The output always looks like: List of Templates and Template Groups assigned to 'somenode.us.dnb.com': |GRP| SBS-DSM Operation successfully completed. It's always on 5 separate lines. How do I extract what follows |GRP| on the third line to a variable? TIA... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reg Exp help
On Feb 26, Busse, Rich said: $Out = `$Cmd` ; The output always looks like: List of Templates and Template Groups assigned to 'somenode.us.dnb.com': |GRP| SBS-DSM Operation successfully completed. It's always on 5 separate lines. How do I extract what follows |GRP| on the third line to a variable? TIA... You could use this: ($text) = `$Cmd` =~ /^\|GRP\|\s*(.*)/m; Let me expand that regex for you: m{ ^# the start of a line \|GRP\| # the text '|GRP' \s* # any whitespace following it (.*) # the rest of the line (non-newline characters) }m # make ^ match at the beginning of a line You could also use `$Cmd` =~ /\n\|GRP\|\s*(.*)/; which works almost exactly the same way. Or, if you know it'll always be the third line... ($text) = (`$Cmd`)[2] =~ /\|GRP\|\s*(.*)/; -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reg Exp help
On Feb 26, Daryl J. Hoyt said: If there is only one of the lines |GRP| this will work. Otherwise I would push the lines into a an array instead of a variable. @Out = `$Cmd`; $WhatFollowsGRP = ; foreach my $line (@Out) { if($line =~ /|GRP|/) You need to escape those |'s. They're special to a regex. { $line =~ s/|GRP|//; Whenever I see if (/foo/) { s/foo//; ... }, I suggest it be shortened to if (s/foo//) { ... } It's less work. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: more reg exp help please
On Feb 8, Stuart Clark said: if ($Charge 0 (($VisaCard|$BankCard),$CreditCard) ) { # This bit doesn't work? What is ((A | B), C) trying to do? Perhaps you want: (($VisaCard || $BankCard) $CreditCard) }elsif ($CreditCard = $Charge 0 ) { # Is ok for a null entry? You need to use eq '', not = ''. If you use =, you will SET $CreditCard to the empty string. You need to COMPARE it with the empty string. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]