Sponsored Content
Top Forums Shell Programming and Scripting compare variable against regular expression? Post 302197950 by finalight on Thursday 22nd of May 2008 02:35:56 AM
Old 05-22-2008
compare variable against regular expression?

is it possible? if so, how?

i want to check a variable whether is it a number or letter in an if-else statement
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

regular expression using a variable

hello, I use AIX with ISM PILOT, I want to match something with a varible like this : $variable = 10 #this variable is the number of the job "$variable STARTED" # the pattern how can use this variable to match it with the word STARTED Tanks (0 Replies)
Discussion started by: barribar
0 Replies

2. Shell Programming and Scripting

Awk's variable in regular expression

Anyone know how I will use awk's variable in a regular expression? This line of code of mine is working, the value PREMS should be a variable: awk '$1 ~ /PREMS/ { if(length(appldata)+2 >= length($1)) print $0; }' appldata=$APPLDATA /tmp/file.tmp The value of APPLDATA variable is PREMS. ... (2 Replies)
Discussion started by: Orbix
2 Replies

3. Shell Programming and Scripting

AWK - compare $0 to regular expression + variable

Hi, I have this script: awk -v va=45 '$0~va{print}' flo2 That returns: "4526745 1234 " (this is the only line of the file "flo2". However, I would like to get "va" to match the begining of the line, so that is "va" is different than 45 (eg. 67, 12 ...) I would not have any output. That... (3 Replies)
Discussion started by: jolecanard
3 Replies

4. Shell Programming and Scripting

Passing Variable to Regular Expression

Hi All, Below is a sample code: print "Enter the Name: "; my $Name = <>; print "Word is $Name"; open (FH,"AIDNameList.txt"); while (<FH>) { my $line; print "Word is $Name"; for $line(<FH>)... (12 Replies)
Discussion started by: jisha
12 Replies

5. Shell Programming and Scripting

How to compare a file name with a regular expression !!

Hi, I need to compare file names in a folder with several strings(which are in regular expression format): For example: there is a file "objectMyHistoryBook" and there are several strings to compare this file name with: objectMyMaths*, objectMyEnglish*, objectMyHistory*,... (2 Replies)
Discussion started by: Lucifer_123
2 Replies

6. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

7. UNIX for Dummies Questions & Answers

grep with variable and regular expression

i have a command line like this in csh script grep -i "$argv$" which i wanted to select the line ending with string provided as argument but it couldn't interpret the '$' (ending with).. any help? (3 Replies)
Discussion started by: ymc1g11
3 Replies

8. UNIX for Dummies Questions & Answers

Compare files with regular expression

Readers, Reading a previous post about comparing files using awk ('awk-compare-2-columns-2-files-output-whole-line', https://www.unix.com/shell-programming-scripting/168432-awk-compare-2-columns-2-files-output-whole-line.html), it is possible to adjust this, so that regular expression can be used... (8 Replies)
Discussion started by: linuxr
8 Replies

9. Shell Programming and Scripting

Regular expression as a variable

I'm trying to use a series of regular expressions as variables but can't get it to behave properly. You can see below what I'm trying to do. Here with lowercase a-z and the same with uppercase, numbers 0-9 and again with a set of special characters, without having to type out every single... (3 Replies)
Discussion started by: 3therk1ll
3 Replies

10. Shell Programming and Scripting

How to store regular expression in a variable?

Hi, Im facing a weird behavior storing regular expression in a vaiable. Let us consider >file_name=CTP02_*.tar when I echo the above variable its displaying below which is file CTP02_*tar but when I create a file with name CTP02_1234.tar, and when I echo $file_name its showing... (3 Replies)
Discussion started by: rdineshredy
3 Replies
re(3pm) 						 Perl Programmers Reference Guide						   re(3pm)

NAME
re - Perl pragma to alter regular expression behaviour SYNOPSIS
use re 'taint'; ($x) = ($^X =~ /^(.*)$/s); # $x is tainted here $pat = '(?{ $foo = 1 })'; use re 'eval'; /foo${pat}bar/; # won't fail (when not under -T switch) { no re 'taint'; # the default ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here no re 'eval'; # the default /foo${pat}bar/; # disallowed (with or without -T switch) } use re 'debug'; # NOT lexically scoped (as others are) /^(.*)$/s; # output debugging info during # compile and run time use re 'debugcolor'; # same as 'debug', but with colored output ... (We use $^X in these examples because it's tainted by default.) DESCRIPTION
When "use re 'taint'" is in effect, and a tainted string is the target of a regex, the regex memories (or values returned by the m// opera- tor in list context) are tainted. This feature is useful when regex operations on tainted data aren't meant to extract safe substrings, but to perform other transformations. When "use re 'eval'" is in effect, a regex is allowed to contain "(?{ ... })" zero-width assertions even if regular expression contains variable interpolation. That is normally disallowed, since it is a potential security risk. Note that this pragma is ignored when the regular expression is obtained from tainted data, i.e. evaluation is always disallowed with tainted regular expresssions. See "(?{ code })" in perlre. For the purpose of this pragma, interpolation of precompiled regular expressions (i.e., the result of "qr//") is not considered variable interpolation. Thus: /foo${pat}bar/ is allowed if $pat is a precompiled regular expression, even if $pat contains "(?{ ... })" assertions. When "use re 'debug'" is in effect, perl emits debugging messages when compiling and using regular expressions. The output is the same as that obtained by running a "-DDEBUGGING"-enabled perl interpreter with the -Dr switch. It may be quite voluminous depending on the complex- ity of the match. Using "debugcolor" instead of "debug" enables a form of output that can be used to get a colorful display on terminals that understand termcap color sequences. Set $ENV{PERL_RE_TC} to a comma-separated list of "termcap" properties to use for highlighting strings on/off, pre-point part on/off. See "Debugging regular expressions" in perldebug for additional info. The directive "use re 'debug'" is not lexically scoped, as the other directives are. It has both compile-time and run-time effects. See "Pragmatic Modules" in perlmodlib. perl v5.8.0 2002-06-01 re(3pm)
All times are GMT -4. The time now is 01:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy