Sponsored Content
Top Forums Shell Programming and Scripting Issue with passing variable to Grep in a shell script Post 302550308 by racshot65 on Thursday 25th of August 2011 09:25:45 AM
Old 08-25-2011
Issue with passing variable to Grep in a shell script

Hi,

I'm trying to check if methods specified in a class have been added to the corrosponding interface.

My code below is giving me the following errors:

Code:
grep: function: No such file or directory
grep: import($zipfile): No such file or directory
grep: function: No such file or directory
grep: export($backup_file: No such file or directory
grep: =: No such file or directory
grep: null): No such file or directory

It looks like grep is trying to use the pattern I'm giving it as the file ? I'm not sure why though

I've made the line where I think the issue is bold

For reference these are the two lines in WorkingClass.txt

Code:
	public function import($zipfile) {
	public function export($backup_file = null) {

and these are the two lines in WorkingInterface.txt

Code:
    public function import($zipfile);
	public function export($backup_file = null);


Code:
#!/bin/bash
#set -x 

# Navigate to the model directory
cd `dirname $0`/../../webapp/_lib/model

#Get the number of lines in the class We need to pipe the output of WC to awk as it prints the name of the file also) 
classLength=$(wc -l WorkingClass.txt | awk '{print $1}')

# Variable to keep track of which line were on
counter=0

# Variable to track if we find the method in the interface
errors=false


#For each method in the class
while [ $classLength -ne $counter ]
do

# Method were looking for
methodToCheck=$(head -1 WorkingClass.txt)
methodToCheck=${methodToCheck/'{'/''}
#echo 'Looking for' $methodToCheck

#Check its in interface
grep -q $methodToCheck WorkingInterface.txt

#echo $?

if [ $? = "0" ]; then
	#remove the top line of working class and increment counter
	sed -i -e "1d" WorkingClass.txt
	#echo 'Found ' $methodToCheck 

else
	#echo $methodToCheck ' not present in ' $interfaceToCheck
	errors=true
	sed -i -e "1d" WorkingClass.txt
fi


#Get the next method
counter=`expr $counter + 1`


done

#echo 'Problems = ' $errors


Any idea how to fix the problem ?

Thanks Smilie

Last edited by pludi; 08-25-2011 at 11:04 AM..
 

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 06:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy