grep commnad


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep commnad
# 1  
Old 12-14-2004
grep commnad

echo "Enter a,: \c"
read answer
echo
case "$answer" in
a|A)
echo "Enter a file :\c"
read $answer
echo " Enter a string to be searched :\c"
read $answer2
if [ ! -s $answer ]
then
echo " file doesn't exist"
else grep $answer2 $answer # is there an alternative way # to declare this ?
fi
;;
# 2  
Old 12-14-2004
I am not much sure with your problem statement. But I assume , you want to search a string within some file.

Alternate way I know is using awk,

awk "/$searchstring/" $file2bSearched
# 3  
Old 12-14-2004
what you've said is what i want to do

but using grep
# 4  
Old 12-14-2004
Quote:
else grep $answer2 $answer # is there an alternative way # to declare this ?

Sry ! Have n't understood yr question properly.


What i would do passing of file and string from commnad from command line and do grep like this

grep $2 $1


also ...what o/p do u want from grep, in yr question ?
# 5  
Old 12-14-2004
props,
Solution I suggested do not involve grep, its an alternative to grep.
# 6  
Old 12-14-2004
Quote:
Originally posted by props
what you've said is what i want to do

but using grep
Why the static requirement that this must be solved using grep? One could well assume that this could be some kind of homework question. Maybe you should try reading the manual page for grep.

Also; your Original Post isn't really a question at all. "Is there an alternative way to declare this". Why do you want to declare it differently? What exactly are you trying to do? What is the purpose of your script? Or is this just what the assignment tells you to do?!

Please review the rules . Looking back through your previous posts it seems you consistently post homework questions on this site, and appear to cause arguments when the point is made. Therefore, I am making the decision to lock this thread before such an argument ensues.

Thanks
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

2. UNIX for Advanced & Expert Users

zsh and watch commnad

Hi Guys i have set the watch command on my shell watch=all but this will report when i open and close a shell, is there a way so that it will ignore me user but only when i am on my machine i can set it to watch=notme but that will not detect if someone su -<my... (0 Replies)
Discussion started by: ab52
0 Replies

3. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

4. Shell Programming and Scripting

how can we perform calculation on the ouput of the commnad

Hello I am very new to unix scripting. The below is the ouput of my one command, now i want to use the two below values 611 and 572 from the output of the command . in the ouput i want 39 which would be come by subtracting 572 to 611. please suggest how can we perform subtraction of... (6 Replies)
Discussion started by: singhald
6 Replies

5. UNIX for Dummies Questions & Answers

User History and commnad log

Dear All I had a UNIX ( Sun solaris ) os. There are many user on that server. Now i want to find during last week who had log in to the sever and which commnad are executed by them? I also want to from which IP they had log in to the server. Is there any log file generated for user in... (5 Replies)
Discussion started by: jaydeep_sadaria
5 Replies

6. UNIX for Dummies Questions & Answers

how to use find commnad to show only path of the result

Hello all say i like to find files i do : find . -name "*.txt" but if i like to find ( and print out ) only the path's where the files are ( the *.txt files ) what can i add to the find command ? (1 Reply)
Discussion started by: umen
1 Replies

7. UNIX for Dummies Questions & Answers

How to apply the awk commnad ?

Hi, I have a file and the contents of the file is say World World World Now i need to append some more words in each of the line and the the output of the file should like the one below Will India win the World Cup? Will India win the World Cup? Will India win the... (3 Replies)
Discussion started by: preethgideon
3 Replies

8. Shell Programming and Scripting

sorting file and unique commnad..

hello everyone.. I was wondering is there a effective way to sort file that contains colomns and numeric one. file 218900012192 8938929 8B8DF3664 1E7E2D59D5 0000 26538 1234 74024415 218900012979 8938929 8B8DF3664 1E7E2D59D5 0000 26538 1234 74024415 218900012992 8938929 8B8DF3664... (2 Replies)
Discussion started by: amon
2 Replies

9. UNIX for Dummies Questions & Answers

Commnad for getting bandwidth usage

Hi all Wanted to know if there is a command that gives me the bandwidth used at any point of time (in mbps). I pay for the bandwidth I have used and need to be alerted everytime I corss over a certain limit. Regards KS (5 Replies)
Discussion started by: skotapal
5 Replies

10. Programming

How does commnad tail implement

How does commnad tail implement ? Thank you . (1 Reply)
Discussion started by: chenhao_no1
1 Replies
Login or Register to Ask a Question