for loop

how to use a for loop to scan one line at a time and grep for a string and print the output.

thanks so much.

You do not loop, just grep which reads line by line

grep 'string to find'  inputfilename

okay , let me rephrase. my bad.

I need to scan a file line by line and print multiple strings as they occur in the file. I know that grep finds the strings in a file and prints all occurences of the first string and then the second and so on.

For eg. if i grep for string "hello" and "howdy" and "ciao" in a file , it prints like below

hello
hello
howdy
howdy
ciao
ciao

I need it to print as they occur on each line like for eg:

hello
howdy
howdy
ciao
hello
ciao

As always , Thanks.

Use the for loop like this.
Remember use back tick inspite of single Quote in for syntax.
Consider the script name as sample.sh.

for i in `cat inputfilename`
do
echo $i
# you can use grep command
done

$ sh sample.sh
Result
will be
displayed
line by line

Try this.