Re: egrep question
- From: Christopher Baker <cbaker@xxxxxxxxxxxx>
- Date: Wed, 7 Feb 2007 14:38:28 -0500
Folks,
I believe we may be missing an issue further up in this code that will not
work.
Look at the for loop on line 22.
If you do a "for name in `cat somefile`
and the lines in some file have spaces, then you WILL get $name that is
Tom
Sawyer
Tale
of
Two
You cannot do it that way. You need to use a while loop and quote your
variable
Actually, this is even easier in PERL.
But, if you want shell program, I can send you an example of how to hand
lines in file1 and file2 that have spaces.... Just have to get back to my
office and pull a few scripts to make sure I don't
lead you astray.
Christopher M. Baker
Senior Technical Support Analyst
HPCE - Linux Cluster Development and Support
Goodyear Tire and Rubber Company
330.796.1725
=================================================
Contains Confidential and/or Proprietary Information.
May not be copied or disseminated without the expressed
written consent of The Goodyear Tire & Rubber Company.
=================================================
Denny Watkins <watkins@xxxxxxxxxxxxxxx>
Sent by: IBM AIX Discussion List <aix-l@xxxxxxxxxxxxx>
02/07/2007 09:13 AM
Please respond to
IBM AIX Discussion List <aix-l@xxxxxxxxxxxxx>
To
aix-l@xxxxxxxxxxxxx
cc
Subject
egrep question
I have two files which have titles of books.
I want to check the book titles in one file to see if the title is in the
other file.
The book titles have spaces, periods, etc.
I wrote a script but I am having a problem getting the title in a form to
'egrep' to the other file.
Titles examples are like:
Tom Sawyer
Tale Of Two Cities
Script is called "check.file.to.file" and is as follows
and is run check.file.to.file name-of-file-1 name-of-file-2
1
2 if [ "$1" = "" ]
3 then
4 arg=0
5 echo "No args..Args are file-name file-to-check"
6 exit
7 else
8 arg=1
9 file1=$1
10 fi
11
12 if [ "$2" = "" ]
13 then
14 echo "Need 2nd argument for file-to-check"
15 exit
16 else
17 file2=$2
18 fi
19
20 # for name in `cat $file1 | cut -f1 -d' '`
21
22 for name in `cat $file1`
23 do
24
25 # egrep -w $name $2 > /dev/null
26 egrep $name $2 > /dev/null
27 grepresult=$?
28
29
30 if (($grepresult == 0))
31 then
32 echo $name " is IN "$2
33 # egrep -w $name $2
34 else
35 echo $name " NOT in "$2
36 fi
37
38 done
Is seems the problem is at line 32. How do you make the $name variable in
line 32
quoted?
Thanks,
Denny Watkins
Morningside College
Phone: 712-274-5250
Email: watkins@xxxxxxxxxxxxxxx
- Follow-Ups:
- Re: egrep question
- From: Christopher Baker
- Re: egrep question
- References:
- egrep question
- From: Denny Watkins
- egrep question
- Prev by Date: Re: initab, process not starting.
- Next by Date: Re: Are there other web sites with the AIX-L list on-line?
- Previous by thread: Re: egrep question
- Next by thread: Re: egrep question
- Index(es):
Relevant Pages
- Re: Errors when reading a file in Bourne shell -- HELP
... I am trying to exit out of the ... the do while and not the shell itself.
... whole shell script. ... to 1 and checking it after the loop. ...
(comp.unix.questions) - Re: trying to understand fork and wait
... old habits based on learning to script in REXX on the ... > the child
reads it. ... situation for me (drop through to bottom/go back to top of loop).
... just to keep a hold of the exit code. ... (comp.lang.perl.misc) - Re: Need to exit loop early
... doing - but it's quite a long script, ... I thought you wanted to exit
the ... > loop, not skip the rest of the code and continue looping. ...
(microsoft.public.scripting.vbscript) - Re: How do I properly use global variables?
... I'd like my program below to change $status to zero to exit the loop. ...
When script is running,how can you re-run it with another argument to ... When you run
it,you can send SIGINT or SIGTERM to let it exit gracefully. ... (perl.beginners) - recreate database script not work
... I got a script which is supposed to regenerate database systax. ... REM
gen_dbse_9.sql ... end loop; ... exit when LOGFILE_CURSOR%NOTFOUND; ...
(comp.databases.oracle.server)