regular expression using a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting regular expression using a variable
# 1  
Old 01-24-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

4. 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

5. Shell Programming and Scripting

passing a regex as variable to awk and using that as regular expression for search

Hi All, I have a sftp session log where I am transferring multi files by issuing "mput abc*.dat". The contents of the logfile is below - ################################################# Connecting to 10.75.112.194... Changing to: /home/dasd9x/testing1 sftp> mput abc*.dat Uploading... (7 Replies)
Discussion started by: k_bijitesh
7 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. 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

8. 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

9. 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

10. Shell Programming and Scripting

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 (6 Replies)
Discussion started by: finalight
6 Replies
Login or Register to Ask a Question
switch(n)						       Tcl Built-In Commands							 switch(n)

__________________________________________________________________________________________________________________________________________________

NAME
switch - Evaluate one of several scripts, depending on a given value SYNOPSIS
switch ?options? string pattern body ?pattern body ...? switch ?options? string {pattern body ?pattern body ...?} _________________________________________________________________ DESCRIPTION
The switch command matches its string argument against each of the pattern arguments in order. As soon as it finds a pattern that matches string it evaluates the following body argument by passing it recursively to the Tcl interpreter and returns the result of that evaluation. If the last pattern argument is default then it matches anything. If no pattern argument matches string and no default is given, then the switch command returns an empty string. If the initial arguments to switch start with - then they are treated as options unless there are exactly two arguments to switch (in which | case the first must the string and the second must be the pattern/body list). The following options are currently supported: -exact Use exact matching when comparing string to a pattern. This is the default. -glob When matching string to the patterns, use glob-style matching (i.e. the same as implemented by the string match command). -regexp When matching string to the patterns, use regular expression matching (as described in the re_syntax reference page). | -nocase | Causes comparisons to be handled in a case-insensitive manner. | -matchvar varName | This option (only legal when -regexp is also specified) specifies the name of a variable into which the list of matches found by | the regular expression engine will be written. The first element of the list written will be the overall substring of the input | string (i.e. the string argument to switch) matched, the second element of the list will be the substring matched by the first | capturing parenthesis in the regular expression that matched, and so on. When a default branch is taken, the variable will have | the empty list written to it. This option may be specified at the same time as the -indexvar option. | -indexvar varName | This option (only legal when -regexp is also specified) specifies the name of a variable into which the list of indices referring | to matching substrings found by the regular expression engine will be written. The first element of the list written will be a | two-element list specifying the index of the start and index of the first character after the end of the overall substring of the | input string (i.e. the string argument to switch) matched, in a similar way to the -indices option to the regexp can obtain. | Similarly, the second element of the list refers to the first capturing parenthesis in the regular expression that matched, and | so on. When a default branch is taken, the variable will have the empty list written to it. This option may be specified at the | same time as the -matchvar option. -- Marks the end of options. The argument following this one will be treated as string even if it starts with a -. This is not | required when the matching patterns and bodies are grouped together in a single argument. Two syntaxes are provided for the pattern and body arguments. The first uses a separate argument for each of the patterns and commands; this form is convenient if substitutions are desired on some of the patterns or commands. The second form places all of the patterns and commands together into a single argument; the argument must have proper list structure, with the elements of the list being the patterns and commands. The second form makes it easy to construct multi-line switch commands, since the braces around the whole list make it unnec- essary to include a backslash at the end of each line. Since the pattern arguments are in braces in the second form, no command or vari- able substitutions are performed on them; this makes the behavior of the second form different than the first form in some cases. If a body is specified as "-" it means that the body for the next pattern should also be used as the body for this pattern (if the next pattern also has a body of "-" then the body after that is used, and so on). This feature makes it possible to share a single body among several patterns. Beware of how you place comments in switch commands. Comments should only be placed inside the execution body of one of the patterns, and not intermingled with the patterns. EXAMPLES
The switch command can match against variables and not just literals, as shown here (the result is 2): set foo "abc" switch abc a - b {expr {1}} $foo {expr {2}} default {expr {3}} Using glob matching and the fall-through body is an alternative to writing regular expressions with alternations, as can be seen here (this returns 1): switch -glob aaab { a*b - b {expr {1}} a* {expr {2}} default {expr {3}} } Whenever nothing matches, the default clause (which must be last) is taken. This example has a result of 3: switch xyz { a - b { # Correct Comment Placement expr {1} } c { expr {2} } default { expr {3} } } When matching against regular expressions, information about what exactly matched is easily obtained using the -matchvar option: | switch -regexp -matchvar foo -- $bar { | a(b*)c { | puts "Found [string length [lindex $foo 1]] 'b's" | } | d(e*)f(g*)h { | puts "Found [string length [lindex $foo 1]] 'e's and | [string length [lindex $foo 2]] 'g's" | } | } | SEE ALSO
for(n), if(n), regexp(n) KEYWORDS
switch, match, regular expression Tcl 8.5 switch(n)