Sponsored Content
Top Forums Shell Programming and Scripting Issue with passing variable to Grep in a shell script Post 302550313 by itkamaraj on Thursday 25th of August 2011 09:48:51 AM
Old 08-25-2011
$methodToCheck --> there may be multiline value in this variable

Code:
grep -q "$methodToCheck" WorkingInterface.txt



---------- Post updated at 07:18 PM ---------- Previous update was at 07:15 PM ----------

Code:
$ a="one two three" 
$ echo $a
one two three

$ echo "one two three four" > mytest

$ grep $a mytest 
grep: two: No such file or directory
grep: three: No such file or directory
mytest:one two three four

$ grep "$a" mytest 
one two three four

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing awk variable to the shell script

hi; i have a file containing lines like: 1|1069108123|96393669788|00963215755711|2|0|941||;serv:Pps6aSyria;first:0;bear i want to extract the second, third and fourth record of each line and store it in a file ";" seperated this is what i wrote while read line do ... (3 Replies)
Discussion started by: bcheaib
3 Replies

2. Shell Programming and Scripting

error in passing a variable to sqlplus from a shell script

hi, I am using a shell script from where i will be conecting to sqlplus.. i am having a problem in passing a variable to sqlplus query.. i will be assigning the variable in the unix environment..whenever i am trying to pass a variable having the contents greater than 2500 characters, i am... (3 Replies)
Discussion started by: kripssmart
3 Replies

3. Shell Programming and Scripting

Passing a regexp to grep via a shell script

Hello, I have the output of ls -l stored in a text file called "files.txt". -rwx------ 1 user1 dev 130 Sep 21 16:14 sc1.sh -rwxr----- 1 user1 dev 10328 Sep 29 20:11 sc10.sh -rwxr----- 1 user1 dev 9984 Sep 30 15:33 sc11.sh -rwxr----- 1 user1 dev ... (2 Replies)
Discussion started by: rogersed
2 Replies

4. Shell Programming and Scripting

Passing parameters to Shell script for GREP command

I am using grep to capture date from a file . Since i need to use the shell script for different dates ,is it possible to pass the date parameter to the shell script the Script is as below grep -E "08 Aug 2008|2008-08-08"* somefile.txt>test.txt The above script file greps the... (1 Reply)
Discussion started by: sud.tech
1 Replies

5. Shell Programming and Scripting

Passing a variable from shell script to mysql query?

I heard this was possible but from my research I haven't been able to figure it out yet. Seems it should be simple enough. Basically from a high level view I'm trying to accomplish... . $X='grep foo blah.log' then 'mysql command SELECT foo FROM bar WHERE ' . $X or something like that. ... (2 Replies)
Discussion started by: kero
2 Replies

6. Shell Programming and Scripting

Passing variable from shell script to python script

I have a shell script main.sh which inturn call the python script ofdm.py, I want to pass two variables from shell script to python script for its execution. How do i achieve this ????? Eg: main.sh a=3 b=3; c= a+b exec python ofdm.py ofdm.py d=c+a Thanks in Anticipation (4 Replies)
Discussion started by: shashi792
4 Replies

7. Shell Programming and Scripting

variable issue in a bash in a shell script

Hi, I am trying to write a PBS shell script that launches a bash process. The issue is that the bash process needs a variable in it and the shell script is interpreting the variable. How do I pass this as a literal string? Here is my code snippit: TMP=".fasta" FILEOUT=$FILE$TMP cd... (2 Replies)
Discussion started by: bioBob
2 Replies

8. Shell Programming and Scripting

Passing shell variable to awk script

I want to pass a shell variable to awk script : # cat file PSAPSR3 3722000 91989.25 2 98 PSAPSR7 1562000 77000.1875 5 95 PSAPUNDO 92000 4087.5625 4 96 #... (8 Replies)
Discussion started by: Reboot
8 Replies

9. Shell Programming and Scripting

Passing value of variable to a query within shell script

I have a script in which i connect to database to run a query and get the result of the query to a temp file. This works fine , now what i want is there is flat file which contains the value to be used in the query. I want to read this file line by line and then run the query for each value in that... (7 Replies)
Discussion started by: gpk_newbie
7 Replies

10. UNIX for Beginners Questions & Answers

How to grep variable in shell script?

Hi Team, I am trying to grep date in a file but it is not working #!/bin/bash d=`date "+ %Y%m%d %H:%M"` cd /scripts /bin/rm -f test1 cat /var/logs/File.txt.0 |grep $"d" >v.txt instead it is showing the complete file output. kindly suggest how should i grep this variable it works... (7 Replies)
Discussion started by: scriptor
7 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 10:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy