Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing file names 1

Status
Not open for further replies.

longhair

MIS
Feb 7, 2001
889
US
good afternoon all,
hpux 11i
any suggestions greatly appreciated.
what i would like to do is find all of the files in a dir that do not have a match based upon the extenstion.
so for example:
ab00123.a
ab00123.b
is ok
but i need to know when there is an ab00123.a and no ab00123.b or vice versa.
i know that i can split the files into 2 seperate files -
Code:
find . -type f -name *.a > file1
find . -type f -name *.b > file2
but don't know how to best compare the 2 files based on the extension or even if this is the best way to approach.
any ideas?
regards,
longhair
 
cd /dira
ls *.a | cut -d\. -f1 >/tmp/lista
cd /dirb
ls *.b | cut -d\. -f1 >/tmp/listb
diff /tmp/lista /tmp/listb

or

cd /dira
for file in $(ls *.a 2>/dev/null)
do
base=$(basename $file .a)
if [ ! -f /dirb/$base.b ]
then
echo $file: $base.b does not exist
fi
done
cd /dirb
for file in $(ls *.b 2>/dev/null)
do
base=$(basename $file .b)
if [ ! -f /dirb/$base.a ]
then
echo $file: $base.a does not exist
fi
done

both untested - typed here on the fly...



HTH,

p5wizard
 
p5wizard,
thanks for the great code! a star for you, your 2nd suggestion is nice & quick & elegant.
regards,
longhair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top