Grep command usage in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep command usage in shell
# 1  
Old 07-28-2008
Grep command usage in shell

hi,

I am facing a problem when i use grep command in shell script.
problem is as follows...

1)i has declared an variable (say a)
2)Now i am searching for an pattern in a file and i used the followig command

cat /wls_../../scripts/log.txt | grep $a-JUL-08

i am not getting any output when i run the above command...

can some one please help out in sorting out the problem of how to pass an variable to grep command..

Thanks in advance.

Regards,
hemanth
# 2  
Old 07-28-2008
swift response would be highly appreciated...
# 3  
Old 07-28-2008
Worked on my HP-UX and CentOS box.

when you type: echo $a does it show you thats in $a?
# 4  
Old 07-28-2008
You don't need to use the cat command (this is not the source of your problem) :
Code:
grep $a-JUL-08 /wls_../../scripts/log.txt

Execute the following commands and show us the output :
Code:
echo "a='$a'"
grep '$a-JUL-08' /wls_../../scripts/log.txt

Jean-Pierre.
# 5  
Old 07-29-2008
Hi Ikon,

yes...when i type echo $a it prints the value thats in $a...

Regards,
hemanth
# 6  
Old 07-29-2008
Hi aigles,

PFB the output of
echo "a='$a'"
grep '$a-JUL-08' /wls_../../scripts/log.txt

output:

a='29

here although log.txt contains data grep is not returning that data.

Regards,
hemanth
# 7  
Old 07-29-2008
Looks like there's a newline at the end of the value of $a, would that explain it? Or did you just fail to copy over the closing single quote?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of shell variable in perl command

Hi, I have a shell script, In which i have variable "var1" and some perl command inside shell script. export var1='coep -n rst-a2p-hinje.vci.all.com -c' perl -pi -e 's/^/coep -n rst-a2p-hinje.vci.all.com -c /' command.txt currently I am adding value of var1 in command.txt file by... (2 Replies)
Discussion started by: rakeshtomar82
2 Replies

2. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

3. Shell Programming and Scripting

How to use grep command in shell script?

Hi, I am new to shell scripting. I had written a small code which accepts config file as parameter. In config file I mentioned a path for input files, INPUT_FILE_FOLDER=/project/dev/con/InputFile SEARCH_MASK_INPUT_FILE=ABC_CR_PQR*.* I want to use this path to get all file names from... (9 Replies)
Discussion started by: Poonamol
9 Replies

4. Shell Programming and Scripting

Usage of grep command to extract only the words.

Dear Folks, I am a newbee to UNIX. I want to extract the SQLSTATE from a log file. For example the log file content is SQL0010N The string constant beginning with "' from table1 a, table 2" does not have an ending string delimiter. SQLSTATE=42603 when I give the the command as ... (4 Replies)
Discussion started by: dinesh1985
4 Replies

5. Shell Programming and Scripting

performance of shell script ( grep command)

Hi, I have to find out the run time for 40-45 different componets. These components writes in to a genreric log file in a single directory. eg. directory is LOG and the log file name format is generic_log_<process_id>_<date YY_MM_DD_HH_MM_SS>.log i am taking the run time using the time... (3 Replies)
Discussion started by: vikash_k
3 Replies

6. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

7. Shell Programming and Scripting

Grep command in shell script

Hi, I have written the following shell script - Error_String="error" var1="| grep -v note1 | grep -v note2" grep -i $Error_String /users/mqm/Pwork/Err/*.out $var1 The above script gives error saying "grep: can't open | grep: can't open grep grep: can't open -v" etc In my program... (3 Replies)
Discussion started by: prasannasupp
3 Replies

8. Shell Programming and Scripting

grep command usage

what is the grep command to get the second occurence of pattern in a file or how to do with sed ? (1 Reply)
Discussion started by: santosh1234
1 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Shell Programming and Scripting

awk and grep command usage

hi Can anyone explain me how these two commands awk and grep works in a ksh shell Thanks Babu (1 Reply)
Discussion started by: ksmbabu
1 Replies
Login or Register to Ask a Question