Expand inside a grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expand inside a grep
# 1  
Old 04-11-2007
Expand inside a grep

Code:
par='one" -e "two'

I want to expand the variable (a little bit more complex) in a grep construction like this (obviously not working):
Code:
ls |grep -e "${par}"

i tried different methods with eval with no result

Is there any way to archive this?

Thx in advance mates!
# 2  
Old 04-11-2007
Klashxx,
See if this would work for you:
Code:
par='one|two'
ls | egrep "$par"

# 3  
Old 04-11-2007
Quote:
Originally Posted by Klashxx
Code:
par='one" -e "two'

I want to expand the variable (a little bit more complex) in a grep construction like this (obviously not working):
Code:
ls |grep -e "${par}"


You do it just for fun, right? Smilie

Code:
$ par='one" -e "two'
$ ls|eval "grep -e \"$par\""
one
two

# 4  
Old 04-11-2007
Both solutions work just fine! I appreciate your help.

Radoulov , it was 50% fun %50 job ... i guessed that eval would be involved .. xP

Thx you guys!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep command inside awk

Hi, I would like to use grep command inside awk. Here is my requirement below : file.txt col1 col2 col3 col 4 col 5 wrxwrx 124 jun 3 Sensex.EMEA wrxwrx 120 jun 4 Emex.US wrxwrx 130 feb 3 passion.AUS wrxwrx 145 feb 9 lession.AUS wrxwrx 130 feb 5 pass.US wrxwrx 130 feb 8... (5 Replies)
Discussion started by: Balasankar
5 Replies

2. Shell Programming and Scripting

wildcard inside regular expression for grep

Hi, I'm on a Linux machine with a bash shell. I have some apache logs from where I want to extract the lines that match this pattern : "GET /dir1/dir2/dir3/bt_sx.gif HTTP/1.1" but where "/dir1/dir2/dir3/bt_sx" may vary , so I would like to grep something like cat apache.log | grep "\"GET... (2 Replies)
Discussion started by: black_fender
2 Replies

3. Shell Programming and Scripting

Help with grep inside an if loop

Hello All, I have been reading posts on here for a while, but this is my first post. I have a document in which many sentences appear, and I am piping it through an exterior script which will tag each word in the document with its part of speech (not part of my script, just background). The... (3 Replies)
Discussion started by: daf189
3 Replies

4. Shell Programming and Scripting

How to grep the contents inside a tar file

Hi All I have searched the possibility of this options everywhere but am unable to find it in any forum. I have a tar file inside which there are n number of files and i dont know them. I need to grep a word inside the tar file and need to know in which file the word resides. > cat a... (2 Replies)
Discussion started by: Whiteboard
2 Replies

5. Shell Programming and Scripting

grep inside if condition - need help

hi i need help with below code. if ] then log "Exiting the script as ID= NULL" log "Please run script first." fi i am calling grep inside this but its not running any ideas why ?? input file is like this -- Msg 102, Level 20, State 1: Server... (4 Replies)
Discussion started by: dazdseg
4 Replies

6. UNIX for Advanced & Expert Users

how to grep/read a file inside compressed tgz without extract?

Hi all, I would like to ask whether in Unix shell/perl have any functions or command to allow grep/cat/read a file inside compressed .tgz without extract it? I know we can tar tvf a compressed tgz but this only allow we read the path/filename contained inside the tarball. If we want to read... (3 Replies)
Discussion started by: mayshy
3 Replies

7. Shell Programming and Scripting

Using grep inside a test

Hi, I want to use grep inside a test statement, but I am getting an error message. Two variables testvarNum=5 testvarNonNum=x echo $testvarNum | grep * The result of this is as follows: 5 However, when I try the following (i.e. to test if the variable is numeric or non-numeric):... (3 Replies)
Discussion started by: dkieran
3 Replies

8. Shell Programming and Scripting

doing grep inside perl file

Hi have one Perl file inside that i am defining at an array file. @temp_vmdk_files = `grep vmdk '$guest_vmx'` where my $guest_vmx=/vmfs/volumes/47e40fec-9c8bb7f7-d076-001422159f8a/BES Exchange/BES-Exchange.vmx and i am just want to do grep of "vmdk" files from the above path but when... (5 Replies)
Discussion started by: bp_vardhaman
5 Replies

9. Shell Programming and Scripting

grep inside the zip file

i have to grep a particular pattern say "meter number" in 100s of zip files file1.zip : : : : file100.zip how to achive this? cat *.zip | grep "meter number" also i dnt want to unzip and then grep it...... hope i made myself clear. thanks in advance (5 Replies)
Discussion started by: ali560045
5 Replies

10. UNIX for Dummies Questions & Answers

how to get the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (1 Reply)
Discussion started by: kripssmart
1 Replies
Login or Register to Ask a Question