Tag Info

New answers tagged

0

I think the answer to this question is in part historic, in part practical. As for the history, Perl is a classy language. It is more classy than Python (not to mention PHP), although I have no idea what is "better" (if that could somehow be formally analyzed, which I doubt). And the classy guys who are using (or used) Perl are typically the guys deciding ...


1

The name given to the filehandle doesn't have any special meaning. Except perhaps when using STDOUT, STDIN or STDERR as filehandle names. FILE works the same as INFILE, though some people may prefer INFILE for readability. See Mat's tip below for a valuable insight into the matter of filehandles. %count is the hash that will be used to store the number of ...


2

Here's how I did it in Perl, although I prefer some of the other answers! use DateTime::Format::Strptime; my $parser = DateTime::Format::Strptime->new( pattern => '%B %d %Y'); m/^(\w+ \d+)/; print $parser->parse_datetime("$1 " . DateTime->now->year)->ymd;


4

This is a bit too roundabout for my taste, but it may be of interest to you: perl -p -e ' BEGIN{ @months=qw(jan feb mar apr may jun jul aug sep oct nov dec); $month_number{$_}=++$i for @months; $months_regex= join "|",@months; } s/^\s*($months_regex)[a-z]*\s+/$month_number{lc $1}-/i' /var/log/syslog This will print (to ...


2

Would this be OK? Every line holding date > 10th and < 18th: awk '$2 > 10 && $2 < 18 {print}' file Including month name: awk '$1 == "May" && $2 > 10 && $2 < 18 {print}' file Span months, April 27th to May 4th: awk '($1 == "Apr" && $2 > 26) || ($1 == "May" && $2 < 5){print}' file Update: ...


3

Using the standard syntax (since the OP mentioned Solaris): sed 's/^\([[:blank:]]*\)\.*/\1/;s/\.*\([[:blank:]]*\)$/\1/' On Solaris, as usual, you may need to call /usr/xpg4/bin/sed or command -p sed


0

$ cat foo .23.12.44.5. .233.3.3.3 line1 23.4.5.3.2.. ....33.2.3.45.5 .3.3.2..... line2 $ sed 's/^ *\.*//;s/\.* *$//' foo 23.12.44.5 233.3.3.3 line1 23.4.5.3.2 33.2.3.45.5 3.3.2 line2


1

Here you go: sed -e 's/^\(\s*\)\.\+/\1/;s/\.\+\s*$//' your_file This will print the modified file to standard output. To write to another file, use: sed -e 's/^\(\s*\)\.\+/\1/;s/\.\+\s*$//' your_file >new_file To modify the file in place, use sed -i -e 's/^\(\s*\)\.\+/\1/;s/\.\+\s*$//' your_file EDIT Modified the regexes to account for ...


0

perl -lane 'print "($F[07]):" eq "$F[8]" ? "@F[0..7]:" : "@F"' This Perl one liner will split the string on spaces, so following string will be split into 9 parts: On dd mmm yyyy hh:mm +hhmm, from info@example.org (info@example.org): It will compare part8 (e-mail address) with part9 (senders name) and if they are same then part8 will be removed. leaving ...


1

Case 1: perl -i -ane '$n=(@F==0) ? $n+1 : 0; print if $n<=2' Case 2: perl -i -ane '$n=(@F==0) ? $n+1 : 0; print $n==2 ? "\n$_" : $n==1 ? "" : $_ '


1

Perl 5 minor versions are backward compatible, so a 5.8.8 module should work with a 5.10.1 perl (but there is an exception, see CAVEAT below). The include path (@INC) is configured in when perl is built, but @INC can be modified by individual programs, and globablly the content of the environment variable $PERL5LIB is prepended. export ...



Top 50 recent answers are included