Comparison in shellscripts.

This idea for a shellscript I have, is just beyond my reach of knowledge.

Basically I have a file that contains a list like so:

axis
heater
water
yast

The file is called mqm.list.

What I want to do is when the shellscript is run, it prompts the user to input data.

Say the person inputs:
axis fire water yast unibrow car truck

I want it to output, only what is on the mqm.list.

So in the example above, the output should be:

axis water yast

Because it matched the mqm.list.

I've tried a bunch of different things, but I'm not getting the concept down. Could someone help me please? Using a test like:

if [ $input = mqm.list ]

isn't working...

Do you want the solution or do you want a push in that direction ?

See man grep. Look at the flags -o and -f. You can use the -o flag alone or in combination with -f flag.

Just a push for now, if I can't figure it out, I'll need a little more help. :o

You may also have a look a -E flag and use regexps... :slight_smile:

Try this, then:

#!/bin/ksh

read line

str="$(echo $line | sed 's/ /\|/g')"

grep -E "$str" ./mqm.list

This works!!!

Can you explain the sed part please?

Of course.
In $line is stored a string consisting of words separated by blanks (" ").
The sed juts changes those blanks into "|" which means "OR" on regular expressions. As you may know, "|" is a special character to the shell that needs to be scaped with a "\". The "g" at the end tells sed to process the whole string, not just the first blank.
Regards.