Using a Regex with double quotations


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using a Regex with double quotations
# 1  
Old 06-27-2012
Using a Regex with double quotations

Hi All,
for a script I'm writing I need to be able to put the following command in a variable:
Code:
tail -30 <file> | egrep "JBoss \(MX MicroKernel\) .* Started"

I thought surround it with single quotes would work. However, it doesnt escape the wildcard, and results in the wildcard being expanded with local files beginning with "."

I've tried a hundred other ways to get this to work. Also some ways result in the correct results when i run echo $containingVar but running the command from the variable gives me this
Code:
$var                                                                                                               
tail: invalid option -- 3
Try `tail --help' for more information.

while entering it as it appears works fine. This one has been driving me crazy so any help would be appreciated!

Last edited by Franklin52; 06-27-2012 at 09:46 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 06-27-2012
How are you exactly initialising the variable "var"? Could you please post the exact line you're using?
# 3  
Old 06-27-2012
various different ways: Here's the line that In my opinion should work:
Code:
$serverCheck='tail -30 /dir1/dir2/dir3/file.log | egrep "JBoss \(MX MicroKernel\) .* Started"'


Last edited by Franklin52; 06-27-2012 at 09:46 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 06-27-2012
Do you want result in variable "serverCheck" or are you evaluating variable "serverCheck" ?

If you want result in "serverCheck" then use
Code:
serverCheck=$(tail -30 /dir1/dir2/dir3/file.log | egrep "JBoss \(MX MicroKernel\) .* Started")

# 5  
Old 06-27-2012
No. I need the resulting command stored in the variable. Not the result.

I invoke it with

$serverCheck

in another part of the script
# 6  
Old 06-27-2012
Rmove sign "$" from the serverCheck
Code:
serverCheck='tail -30 /dir1/dir2/dir3/file.log | egrep "JBoss \(MX MicroKernel\) .* Started"'

# 7  
Old 06-27-2012
thats the same code I wrote above. It doesn't work. The wildcard is expanded to include locale files. I use the '$' only when I want to call the resulting command.

---------- Post updated at 08:55 AM ---------- Previous update was at 08:55 AM ----------

my mistake. that's not what i wrote above. But above was a typo. I didn't put a '$'. Instead I've been putting what you wrote. Still doesnt work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output with quotations

I will invoke a shell script.bash -x ./00_remove_tenants_FR_BE_instanceData.sh CGD2ICON CGDEV2 50005 cgdev2@123 I need a string of "cgdev2/'cgdev2@123'@localhost:50005/cgd2icon" parameters ==> 2nd 4th 3rd ... (3 Replies)
Discussion started by: pranabpal
3 Replies

2. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

3. Shell Programming and Scripting

Perl, RegEx - Help me to understand the regex!

I am not a big expert in regex and have just little understanding of that language. Could you help me to understand the regular Perl expression: ^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{ ------ This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Discussion started by: alex_5161
2 Replies

4. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

5. Shell Programming and Scripting

Help with nested $s and quotations in bash / awk

Folks - newbie bash coder here and I'd like to get your help to make the code below work. As you can see, I was trying to count the total number of lines with the 3rd value >= 15 in a file and wanted to make the threshold "15" configurable, but apparently the $THRESHOLD value was not populated... (3 Replies)
Discussion started by: bashzipper
3 Replies

6. UNIX for Dummies Questions & Answers

read regex from ID file, print regex and line below from source file

I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header. In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

7. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

8. Shell Programming and Scripting

changing the output of ls to use quotations

Hi, this is on mac osx. Im using this to find all mp3 files in my downloads folder. I would like to then add these files to itunes ls -R | grep .mp3 I would then do soemthing like for x in `ls -R | grep .mp3`; do open -a itunes done then it says the file... (2 Replies)
Discussion started by: tepinvic
2 Replies

9. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

10. Programming

double pow (double x, double y) -- problems

This is the code and I'm wondering why line 14: a = ... and line 16: b = ... is wrong. This is the first time I've tried to use this. Please help me. #include <stdio.h> #include <math.h> // The link and how the double pow is used. // // http://www.nextdawn.nl/c-reference/pow.php //... (2 Replies)
Discussion started by: pwanda
2 Replies
Login or Register to Ask a Question