LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   perl case sensitivity (https://www.linuxquestions.org/questions/programming-9/perl-case-sensitivity-760863/)

cmontr 10-09-2009 04:50 PM

perl case sensitivity
 
Hi Guys,

When use this liner code, anyway to print "TeSt" in case insentive?

ie. it should print all "test, Test, TEST etc..."

Code:

perl -s -ne '($user,$ou) = /.*uid=(.*?), ou=(.*?),.*/ if /^dn/; print "$user\n" if /^stat: 2/ && $ou eq "test";' infile


Thanks

ghostdog74 10-09-2009 06:51 PM

please read perldoc perlre (from now on). There is a modifier to do case insensitivity in Perl's regex.

Telemachos 10-09-2009 07:35 PM

Instead of testing for string equality ($string eq 'test'), you should use a regular expression with the i flag.

Code:

telemachus ~ $ cat file
test
TeSt
TEst
tesT
TEsT
TEST
gotcha
telemachus ~ $ perl -nle 'print if $_ =~ /test/i' file
test
TeSt
TEst
tesT
TEsT
TEST

See perldoc perlrequick for a good introduction to regular expressions.


All times are GMT -5. The time now is 11:14 PM.