grep returns many values into a variable error


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep returns many values into a variable error
# 1  
Old 03-15-2011
grep returns many values into a variable error

I get an error when I grep my results into a variable when the grep finds more than one file.
Code:
FND="$(find ediout* -mmin -60)"
    if [ $FND > '' ]; then
         STR="$(find ediout* -mmin -60 -exec grep -l   "ERRORS Encountered" {} +)"
    fi

When there is only one ediout file it works fine. How do I get around this?

Last edited by joeyg; 03-15-2011 at 09:55 AM.. Reason: Please wrap comands with CodeTags to maintain formatting
# 2  
Old 03-15-2011
You probably meant this:
Code:
FND="$(find ediout* -mmin -60)"
if [ -n "$FND" ]; then
     STR="$(find ediout* -mmin -60 -exec grep -l   "ERRORS Encountered" {} +)" 
fi

Beware the > sign is not used for comparison but for file redirection, you tried to write to the '' file ...

Not sure if the syntax of your STR=... line is correct, but if it works I wouldn't change it without knowing exactly your need
# 3  
Old 03-15-2011
error with new code

I included your new code and I get the following error:
Code:
/edierror.sh[43]: test: 0403-004 Specify a parameter with this command.

please advise.

Last edited by Scott; 03-16-2011 at 03:48 PM.. Reason: Code tags
# 4  
Old 03-16-2011
Quote:
Originally Posted by aispg8
/edierror.sh[43]: test: 0403-004 Specify a parameter with this command.
The error may come from your actual code and not the code you included.
Please post the complete code (specifically around line 43)
# 5  
Old 03-16-2011
The error line 43 =
Code:
"echo "${STR}" | mailx -s "EDI Translation Errors List" test@optonline.net"

The full code =
Code:
    FND="$(find ediout* -mmin -60)"
    if [ $FND > '' ]; then
         STR="$(find ediout* -mmin -60 -exec grep -l "ERRORS Encountered" {} +)"
    fi
#   email the results
    if [ $STR > '' ];  then
        echo "${STR}" | mailx -s "EDI Translation Errors List"  test@optonline.net        The following file(s): ${STR} may contain errors during translation.
MAILER
    fi


Last edited by Scott; 03-16-2011 at 03:49 PM.. Reason: Code tags
# 6  
Old 03-16-2011
Quote:
Originally Posted by aispg8
The error line 43 =
# email the results
if [ $STR > '' ]; then
Given the error message and the line above ...
# 7  
Old 03-16-2011
Could be better using a workfile for the results not an environment variable.

Code:
find ediout* -mmin -60 -exec grep -l "ERRORS Encountered" {} + > /tmp/results
if [ -s /tmp/results ]
then
      cat /tmp/results | mailx -s "EDI Translation Errors List" test@optonline.net
fi
rm /tmp/results

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

error while updating rows in sql with values in array variable

Hi, I need to update rows in a table based on the values in an array variable. code is : while read line do error_msg="$(echo $line)" index=`expr $index+1` done <"logs/$ffile" rows_count=${#error_msg } i=0 while do echo "error msgs is... (2 Replies)
Discussion started by: RP09
2 Replies

2. Shell Programming and Scripting

Function returns a value but cannot be stored in other variable

I need help to store the value returned from the function to one variable and then use that variable. PREVIOUS_DATE_FUNCTION() { date '+%m %d %Y' | { read MONTH DAY YEAR DAY=`expr "$DAY" - 1` case "$DAY" in 0) MONTH=`expr "$MONTH" - 1` case... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

3. Shell Programming and Scripting

If test grep.... always returns 0 status

Hi all. I am trying to compare and filter two files. I have a bigfile.txt of names and ids and a smallfile.txt of ids only. What I am trying to do is use a while read loop to read the ids in the bigfile and then echo the name and id only if the id exists in the small file. Basically, I'm trying to... (5 Replies)
Discussion started by: jameswatson3
5 Replies

4. Shell Programming and Scripting

sqlplus returns leading carriage return into a variable

I am trying to generate some scripts to help manage an Oracle database. When I check the value returned from Oracle it has a leading carriage return in the variable. Is there a way to prevent this? Is there a way to easily strip out the carriage return. See code and output below. ... (7 Replies)
Discussion started by: Panzer993
7 Replies

5. Shell Programming and Scripting

Using grep returns partial matches, I need to get an exact match or nothing

I’m trying to modify someone perl script to fix a bug. The piece of code checks that the zone name you want to add is unique. However, when the code runs, it finds a partial match using grep, and decides it already exists, so the “create” command exits. $cstatus = `${ZADM} list -vic | grep... (3 Replies)
Discussion started by: TKD
3 Replies

6. Shell Programming and Scripting

Grep returns nothing

Hi all, I am trying to grep a .txt file for a word. When I hit enter, it returns back to $ The file is 4155402 in size and is named in this way: *_eveningtimes_done_log.txt I use this command, being in the same directory as the file: grep -i "invalid" *_eveningtimes_done_log.txt ... (16 Replies)
Discussion started by: DallasT
16 Replies

7. Shell Programming and Scripting

If the grep command returns any result set

my intension is to use a grep command inside the shell script and if any row is returned or not.. depending on the resultset i have to code on further. how to check this i mean.. could anyone help me out with the if condition how to use it here !! (4 Replies)
Discussion started by: gotam
4 Replies

8. Shell Programming and Scripting

Function returns wrong values - solved

Hi I have a small function which returns a wrong value. The function tries to make a connection to oracle database and tries to get the open_mode of the database in the variable status. However when a database is down the value of the status column is set to READWRITE i am not sure why. I... (0 Replies)
Discussion started by: xiamin
0 Replies

9. Shell Programming and Scripting

find/grep returns no matches

Hi all! I've faced with very unintelligible error using find/grep like this: root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507I get nothing as a result, but: root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc $db_name = 'u28507';... (2 Replies)
Discussion started by: ulrith
2 Replies

10. UNIX for Dummies Questions & Answers

Grep without returns...

Is there a command where I can pipe my grep into it and it will output it with spaces rather than returns? Example I want to turn prompt$ grep blah file blah blah into this prompt$ grep blah file | someCommand blah blah (1 Reply)
Discussion started by: mrwatkin
1 Replies
Login or Register to Ask a Question