Sponsored Content
Top Forums Shell Programming and Scripting If test grep.... always returns 0 status Post 302532877 by jameswatson3 on Wednesday 22nd of June 2011 09:35:57 AM
Old 06-22-2011
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 find the names that correspond to the ids in the small file.

Here's what I've got so far:
Code:
big=bigfile.txt
small=smallfile.txt

while read user id
do
    if test 'grep -q $id $small'; then
        echo "ID exists"
    else
        echo "ID does not exist"
    fi
done < $big

My problem now is that the first condition is always evaluated as true. No matter whether the id exists or not in the smallfile, the output is always the same - "ID Exists" for every line of input in bigfile.

I've manually confirmed that the exit code should be non-0 for multiple ids in bigfile. Any ideas on what I'm doing wrong?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

test: unknown operator status

hi I get test: unknown operator status if then echo "OK." return 0 else echo "not ok" 2>&1 exit -1 fi I tried to change "A" with 'A' --> same error I tried to change if , I am getting: (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

2. Shell Programming and Scripting

if returns "unknown test operator"

Greetings, using ksh on Solaris, I am trying to identify the current version of a package installed on multiple servers using if statement in a precursor to upgrading. I have searched the forums and have found many hits, reviewed 3 pages and have tried the different variations noted there. Also... (3 Replies)
Discussion started by: 22blaze
3 Replies

3. 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

4. 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

5. 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

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. UNIX for Dummies Questions & Answers

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. FND="$(find ediout* -mmin -60)" if ; 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... (11 Replies)
Discussion started by: aispg8
11 Replies

8. Shell Programming and Scripting

How to test for the ssh exit status in script?

Hello; I regularly run monitoring scripts over ssh to monitoring scripts But whenever a server is hung or in maintenance mode, my script hangs.. Are there anyways to trap exit status and be on my way ?? Looked at the ssh manpage and all I can see is a "-q" option for quiet mode .. Thank... (2 Replies)
Discussion started by: delphys
2 Replies

9. Shell Programming and Scripting

Test exit status of last cmd via ssh

see below for a housekeeping script which constructs an ssh cmd using some server/path/sudo info found in $HRINST. the script should hop to each server and if it finds a file to cleanup, moves it to the archive dir if there is nothing to move, it should report so and email the output ... (3 Replies)
Discussion started by: jack.bauer
3 Replies

10. Shell Programming and Scripting

Test with non-zero status does not exit shell

Hi there, I'm very used to use set -e to break my scripts if any command exits with a non-zero status. As a policy, I'm willingly expecting echo hello | grep a to break the script. The commands test 1 -eq $1 && echo hello exits with a non-zero status if $1 is not 1. BUT... It doesn't break... (2 Replies)
Discussion started by: chebarbudo
2 Replies
GLGENQUERIES(3G)						    OpenGL 3.3							  GLGENQUERIES(3G)

NAME
glGenQueries - generate query object names C SPECIFICATION
void glGenQueries(GLsizei n, GLuint * ids); PARAMETERS
n Specifies the number of query object names to be generated. ids Specifies an array in which the generated query object names are stored. DESCRIPTION
glGenQueries returns n query object names in ids. There is no guarantee that the names form a contiguous set of integers; however, it is guaranteed that none of the returned names was in use immediately before the call to glGenQueries. Query object names returned by a call to glGenQueries are not returned by subsequent calls, unless they are first deleted with glDeleteQueries(). No query objects are associated with the returned query object names until they are first used by calling glBeginQuery(). ERRORS
GL_INVALID_VALUE is generated if n is negative. GL_INVALID_OPERATION is generated if glGenQueries is executed between the execution of glBeginQuery() and the corresponding execution of glEndQuery(). ASSOCIATED GETS
glIsQuery() SEE ALSO
glBeginQuery(), glDeleteQueries(), glEndQuery() COPYRIGHT
Copyright (C) 2005 Addison-Wesley. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/. OpenGL 3.3 03/08/2011 GLGENQUERIES(3G)
All times are GMT -4. The time now is 05:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy