944,142 Members | Top Members by Rank

Ad:
Dec 2nd, 2004
0

Using find in a bash shell script

Expand Post »
I recently ran the following command from the command line and it worked
find . -name '*jrAPS*_ouput.log' -exec grep '<string expression>' {}\; -print

I put it in a shell script like this and it did not work
find . -name \'*jrAPS*_output.log\' -exec grep \'<string expression>\' {} \\\; -print

the result was find: incomplete statement why?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iparkin is offline Offline
11 posts
since Dec 2004
Dec 2nd, 2004
0

Re: Using find in a bash shell script

On my system, I don't need to perform all the escaping that you are doing. The same command that I use on the command line works in the shell script because nothing is interpreting the command before executing it. However, if you have another shell reading commands from this script and executing them, then you would need the escapes. If that doesn't help use bash -n $0 where $0 is your current command line to see if you have syntax errors before running. Sometimes the error messages are slightly different (or more of them) when just analyzing.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
coca-light is offline Offline
2 posts
since Dec 2004
Dec 3rd, 2004
0

Re: Using find in a bash shell script

Thanks I will do that do you know any Linux servers I can get access to on the net to try this.?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iparkin is offline Offline
11 posts
since Dec 2004
Dec 3rd, 2004
0

Re: Using find in a bash shell script

Sorry, I don't know of any public Linux Servers.
If you need an easy install try Xandros Open Edition. You answer 5 or 10 questions, wait about 30 minutes and voila instant Linux - with sound and networking. http://www.xandros.com
Reputation Points: 10
Solved Threads: 1
Newbie Poster
coca-light is offline Offline
2 posts
since Dec 2004
Dec 3rd, 2004
0

Re: Using find in a bash shell script

Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 163
The Queen of DaniWeb
cscgal is offline Offline
13,646 posts
since Feb 2002
Dec 4th, 2004
0

Re: Using find in a bash shell script

Thanks I will check out these sites
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iparkin is offline Offline
11 posts
since Dec 2004
Dec 5th, 2004
0

Re: Using find in a bash shell script

Here is the shell script I am trying to run in bash

if [ $# -neq 1 ];
then
echo "Usage: <program name> <string expression>"
exit 1
fi

findstr=$1
echo "$findstr"

find . -name 'm1_jrAPS*_output.log' -exec grep \'"$findstr"\' {} \; -print


In the above script I want to take the string from the command line and put it in the find command in the shell script I have a hard time getting the shell to expand it in single quotes like in the regular command
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iparkin is offline Offline
11 posts
since Dec 2004
Dec 19th, 2004
0

Re: Using find in a bash shell script

I found an easier solution using command substitution and looping.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iparkin is offline Offline
11 posts
since Dec 2004
Jul 6th, 2010
0
Re: Using find in a bash shell script
Hi,
Im having a similar problem here.
Im trying to make a script:

[code]
#/bin/bash
teste="{33,351}";
ls -laht /tmp/interface*_${teste}_*.xml
[icode]

but it gives an error. If i change ${teste} for the static value itself it works.

Any idea? I've tried to evaluate with the $() but it doesnt work.

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
edup_pt is offline Offline
16 posts
since Jul 2010
8 Days Ago
0

That I would do with xargs

find . -name \'*jrAPS*_output.log\'|xargs egrep "a regular expresion"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
borlam is offline Offline
1 posts
since Feb 2012

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Shell Script Tasks
Next Thread in Shell Scripting Forum Timeline: Need help using tr and cut file to another file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC