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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Complete or Auto Capitalize

Status
Not open for further replies.

CTC

Programmer
Nov 24, 2001
3
US
Hi There,

Does anyone know if unix/awk have the capability to make a user's input autocomplete? For example the user was asked to input a topic. All possible topics are listed in file1. When the user's first letter inputs match a content of file1, the word autocompletes.

How do we auto capitalize all user's input once the script is run??

Thanks!

-CTC
 
Need to think about autocomplete, but for capitalising, you can pipe the output through tr. For example

echo "capitalise this" | tr "[:lower:]" "[:upper:]"

That's one way anyway.

Greg.
 

Hi CTC!

Here is my awk solution for capitalising user's input:

Code:
# inp_toup.awk - input with gawk
# inp_toup.awk - upis podataka s gawk-om
# Kruno Peter, kruno_peter@yahoo.com
# gawk, Public Domain
# Jesus loves you.

BEGIN  {

    while ( inputData == ""  )  {
        printf ( "You can type here: " )
        getline inputData
    }

    uppData = toupper(inputData)
    print ( "The input is: ", uppData )
}

I use DOS, Win and Linux versions of gawk (GNU, thanks! God bless you.). Function toupper and command getline are available in gawk and nawk, but not in initial awk version. Function toupper translates all lowercase characters to uppercase.

I hope this helps.

Bye!

KP.
 
There are a couple of problems with the autocomplete idea that I can see just from playing with it.
You could iterate through a file looking for pattern matches line by line; something like this:

awk ' {
printf "String to match: "
getline str < &quot;-&quot;
if (str) {
my_str = toupper(substr(1,1,str)) #getch() type
}
for (x=0 ; x <= NR ; x++)
if ($x ~ my_str) {
print NR, &quot;:&quot;, $0
} else {
nomatches = NR
nomatches++
}
}' filename

But this is just a guess, I haven't tested it well..
You could also pass the string to awk as a shell variable
or parameter and then do what you want with it: that should work better.

say
awk '
char = substr(1,1,ARGV[2]) or something.
etc..
}'
or :
while :
do
read char
awk -v x=$char ' {
xx = toupper(x)
if ($0 ~ xx) {
print
}
}' filename
if [ &quot;$char&quot; = &quot;&quot; ]
then
exit > /dev/null
fi
done


Good Luck


 
Thanks guys!!! I'll try this out
-CTC =D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top