Re: egrep question
- From: Christopher Baker <cbaker@xxxxxxxxxxxx>
- Date: Wed, 7 Feb 2007 16:07:22 -0500
Denny,
Here is probably the dorkiest way to do this, but it will give you the
whole title in one variable:
cat file1 | while read name
do
echo "$name"
done
Just don't forget to use quotes around the variable name, "$name" so that
grep or egrep or echo uses the whole string
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.
=================================================
Christopher Baker <cbaker@xxxxxxxxxxxx>
Sent by: IBM AIX Discussion List <aix-l@xxxxxxxxxxxxx>
02/07/2007 02:38 PM
Please respond to
IBM AIX Discussion List <aix-l@xxxxxxxxxxxxx>
To
aix-l@xxxxxxxxxxxxx
cc
Subject
Re: egrep question
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
- References:
- Re: egrep question
- From: Christopher Baker
- Re: egrep question
- Prev by Date: Re: Are there other web sites with the AIX-L list on-line?
- Next by Date: Seeking trainers and/or courseware resources
- Previous by thread: Re: egrep question
- Next by thread: Re: egrep question
- Index(es):