Equivalent to Perl's and Bash's "=~" Operator?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Equivalent to Perl's and Bash's "=~" Operator?
# 1  
Old 07-24-2012
Equivalent to Perl's and Bash's "=~" Operator?

Hello All,

Alright, so this is driving me absolutely insane. I can't seem to find this ANYWHERE...
I've tried every combination and synonym I can think of for this trying to search Google.

What is the Expect/Tcl equivalent to Perl and Bash's "=~" operator, (i.e. the "contains" operator).
I'm trying to do an if statements to check if a line contains a specific string, and the only operators I could find anywhere for Expect are (==, !=, <=, >=, <, >)...

Anyone have any clue if it's possible to do a pattern match in an Expect Script's if statement?
Any thoughts would be much appreciated.

Thanks in Advance,
Matt
# 2  
Old 07-24-2012
It's not a "contains" operator, it's a regular expression operator.

I don't think TCL has an operator for it, but it does seem to have a command.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 07-24-2012
Hey Corona, thanks for the reply.

Right, sorry didn't mean to call it the contains operator, I was just trying to simplify... Shoulda said REGEX or Pattern Matching.

But anyway, I just checked out your link and I think that may be what I need. I'll give it a try and post back if it worked.

Thanks for dulling down my frustrations a bit lol...
I couldn't find a darn thing in google for Tcl or Expect that showed anything other then an exact match in an if statement or greater/less thens...


Thanks Again,
Matt

---------- Post updated at 03:41 PM ---------- Previous update was at 03:33 PM ----------

Hey Again Corona... Victory!

Thanks that worked..!

Here's what it should look like for anyone with a similar problem:
Basically it loops through the output from the previous send command, line by line.
Code:
set myString "foo"
:....
:.....
    # Loop through the previous send command's output line-by-line
    foreach line [split $expect_out(buffer) "\n"] {
        # If the current line contains $myString, then...
        if {[regexp ".*$myString.*" $line]} {
                puts "FOUND WHAT I'M LOOKING FOR!"
        }
    }

This User Gave Thanks to mrm5102 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

3. Shell Programming and Scripting

perl's substitution operator "s" with file contents?

Please show me how to make substitution over the contents of a file in a perl script. In a perl script, the core part of substitution operation is s/FINDPATTERN/REPLACEPATTERN/g; However, I cannot figure out how to make the substitution occur over the contents of a file. The following... (3 Replies)
Discussion started by: LessNux
3 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

What "-a" operator means in "if" statement

Hi I am trying to figure out what the following line does, I work in ksh88: ] && LIST="$big $LIST" Not sure what "-a" means in that case. Thanks a lot for any advice -A (1 Reply)
Discussion started by: aoussenko
1 Replies

6. Shell Programming and Scripting

What is the ksh equivalent to bash's "history -c" command?

Hi, What is the korn shell equivalent of bash shell's "history -c" command? I do know, how to clear the history list in ksh, I can do the following: > ~/.sh_historybut still, I am interested to know the single one line command as 'history -c' gives error on my ksh (1 Reply)
Discussion started by: royalibrahim
1 Replies

7. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

8. Shell Programming and Scripting

cannot properly employ "or" operator in an if statement (bash)

Hi, I have a variable, $sername, and I would like to display this variable only if it *does not* contain either of these two tags: *DTI*FA* or *DIFF*FA*. I think the syntax for my 'or' operator is off. The variable $sername is continuously changing in an outer loop (not shown), but at the... (4 Replies)
Discussion started by: goodbenito
4 Replies

9. UNIX for Dummies Questions & Answers

the equivalent of perl's "\s" in sed

Hi: I am a little bit surprised to learn that there is no equivalent of "\s" (blank space) in sed. How do you represent all types of blank in sed, including " ", "\t", "\n" etc? Thanks. (1 Reply)
Discussion started by: phil518
1 Replies

10. UNIX for Advanced & Expert Users

Commands on Digital Unix equivalent to for "top" and "sar" on other Unix flavour

Hi, We have a DEC Alpha 4100 Server with OSF1 Digital Unix 4.0. Can any one tell me, if there are any commands on this Unix which are equivalent to "top" and "sar" on HP-UX or Sun Solaris ? I am particularly interested in knowing the CPU Load, what process is running on which CPU, etc. ... (1 Reply)
Discussion started by: sameerdes
1 Replies
Login or Register to Ask a Question