Operating System - HP-UX
1834613 Members
4072 Online
110069 Solutions
New Discussion

Re: comparing files using awk

 
Kurtkarl
Frequent Advisor

comparing files using awk

Hi,

I'm not a script guy and I'm currently in a situation which is, I need someone who could help me create a simple (for the experts) awk script that will compare system files against users input.

ex. - users entered "SAMPLE.TXT" (usually
upper case)
- systems could have "Sample.txt"
or "sample.txt"
or "sample.TXT"

regardless whatever the system has. Script should match users input against files in the system and proceed it's process. BTW, this is to ftp a file from one machine to another.

Your reply would be greatly appreciated.
Thanks
Joey
Just starting to learn thru this forum
3 REPLIES 3
Robin Wakefield
Honored Contributor

Re: comparing files using awk

Hi Joey,

This may not be what you want, and it doesn't use awk, but it'll find all files under a directory, regardless of case, that match the user's input:

================================
#!/bin/ksh

DIR=search-directory

echo Enter filename: '\c'
read FILENAME

find $DIR -type f | grep -i "/${FILENAME}$"
==================================

Obviously, you need to edit the "DIR=" line.

Rgds, Robin.
Bill McNAMARA_1
Honored Contributor

Re: comparing files using awk

the grep -i option means case insensitive btw.

You probably want the

awk tolower(string) or toupper(string)

but I'll leave it to Robin, to sort that out for you.. he's the awk guru here.. I'm very surprised he didn't come out with it in his earlier post.. usually if there's a question such as how do I change directory, Robin will give you an awk script before telling you about cd !!! ;)

Later,
Bill

It works for me (tm)
Deepak Extross
Honored Contributor

Re: comparing files using awk

Joey,
You don't need awk for this. Is there some compelling reason for you to use awk?
Methinks Richard's "grep -i" should do the trick nicely.