How to make command line interactive?

I have a file with stats for different month, I use the cat and grep combination to search for different month.

cat <file> | grep "April"
cat <file> | grep "May"
cat <file> | grep "June"
etc.

How do you make this command interactive. So that I can give the values for the search. Thanks for your help.

Example

cat <file> | grep "&input_month"

Try this script:

#!/bin/bash
printf "Enter month: "
read month
grep "$month" <file>

Do I need write a .sh file and submit?

Anyway I could accomplish this in command prompt...

For example

$cat <file> | grep "&input_month"

>then I input : April

On command line:

# read month; grep "$month" <file>
1 Like

Also could I read multiple fields say month and file name?

# read month file; grep "$month" "$file"

Thanks

You can read multiple fields:

read month file; 
May filename.txt<ENTER>; 
grep "$month" "$file"
1 Like

How do I store the following in .profile file, so that I can easily invoke and not type the whole line evertime?

I am only asking as I do this in various directories several times a day.

read month file; grep "$month" "$file"

---------- Post updated 05-04-11 at 02:52 PM ---------- Previous update was 05-03-11 at 03:09 PM ----------

How do I store the following in .profile file, so that I can easily invoke and not type the whole line evertime?

--
read month file; grep "$month" "$file"
--

I am only asking as I do this in various directories several times a day.

You agreed not to bump posts when you registered. If you don't get an answer the instant you post, wait. None of us are "on call" here.

What is your system? What is your shell?