How to make command line interactive?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make command line interactive?
# 1  
Old 04-28-2011
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"
# 2  
Old 04-28-2011
Try this script:
Code:
#!/bin/bash
printf "Enter month: "
read month
grep "$month" <file>

# 3  
Old 04-28-2011
Quote:
Originally Posted by bartus11
Try this script:
Code:
#!/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
# 4  
Old 04-28-2011
On command line:
Code:
# read month; grep "$month" <file>

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 05-03-2011
Also could I read multiple fields say month and file name?

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

Thanks
# 6  
Old 05-03-2011
Quote:
Originally Posted by purelltab
Also could I read multiple fields say month and file name?

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

Thanks
You can read multiple fields:
Code:
read month file; 
May filename.txt<ENTER>; 
grep "$month" "$file"

This User Gave Thanks to kevintse For This Post:
# 7  
Old 05-04-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help make pkgadd command Non-Interactive

i use this command to make pkgadd non-interactive. Command1: echo | sudo /usr/sbin/pkgadd -n -a /u/base/admin -r silent.txt -d /tmp/dbs.pkgThis works fine if i run it as root user but when i run it with non-root user it prompts me for the password and then executes successfully thus making it... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. Homework & Coursework Questions

Make a file accept only two arguments from the command line

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) The script is executed in the Korn shell. 2) Name the shell script file is asg6s. 3) The asg6s file is... (7 Replies)
Discussion started by: ProgMan2015
7 Replies

3. Programming

Make a file accept only two arguments from the command line

DELETED (2 Replies)
Discussion started by: ProgMan2015
2 Replies

4. Shell Programming and Scripting

Homework: Make a one-line Unix command - using pipe(s)

Task A: Make a one-line Unix command - using pipe(s) - to display the number of files in your home directory including the hidden files that begin with '.' Task B:Make a one-line Unix command - using pipe(s) - to display the number of unique zip codes in famous.dat (hint: use -u on sort) Task... (1 Reply)
Discussion started by: wises
1 Replies

5. AIX

Non interactive command output using script command ?

Hello, Script command helps to save command output to file. (Redicection doesn't work in this case). Besides interactive shell 'recording', Linux script command has "-c" option which allows to record output of some non-interactive command. The problem is that AIX script command variant... (6 Replies)
Discussion started by: vilius
6 Replies

6. Homework & Coursework Questions

I need to make a script that has 4 command line arguments to function properly.

I have no idea what the following means. The teacher is too advanced for me to understand fully. We literally went from running a few commands over the last few months to starting shell scripting. I am not a programmer, I am more hardware oriented. I wish I knew what this question was asking... (3 Replies)
Discussion started by: Wookard
3 Replies

7. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

8. Shell Programming and Scripting

How to make interactive shell script a automated one?

Hi, I am new to shell scripting.I have written a very simple shell scipt that asks for the username and password on executing. i.e echo "Enter username :" read usrname; echol "Enter password :"; read passwd; echo usrname; echo passwd; but now I want to make it automatic , such... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

9. Linux

how to enable #ifdef macro in the command line of make?

Linux, C++, make, macro In source code, we used some #ifdef macros. How can I enable #ifdef macro in the command line of "make" (NOTE: I do NOT want to change source code or makefile to define that macro from time to time). e.g. test.cpp: ... #ifdef TEST1 // code segment for test1 ...... (3 Replies)
Discussion started by: princelinux
3 Replies

10. Shell Programming and Scripting

How to make a cshell (csh) script interactive

Experts, I tried to make my cshell script interactive by asking the user for password and trying to read the input using the "read" command. I have been unsuccessful so far. Do you have any idea ? Thanks Jim (2 Replies)
Discussion started by: jimmynath
2 Replies
Login or Register to Ask a Question