![]() |
How do I program in shell script for write a word if it finds another word
I have a file named medpre.msg.log
Script should search for a word 'degenerated' If it finds the word 'degenerated' , then it should write 'ECHT' on already existing file Mcheck.prot How should I write the program, please help me . I am new to shell scripting Thank you in advance......:) |
Please show us what you have done so far and we'll point you in the right direction.
In the meantime, here are some useful links http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ Have a look at the grep cmd http://linux.die.net/man/1/grep |
Sorry I have not done anything so far , I need help extensively to do this program..
I have a file medpre.msg.log in the path /home/balnair/.medina/medpre.msg.log and another file in the path /home/transfer/Mcheck.prot script should search for the word 'degenerated' in medpre.msg.log If it finds it should append 'ECHT' to file Mcheck.prot So how can be done log_file = " /home/balnair/.medina/medpre.msg.log " work = "/home/transfer/Mcheck.prot" if [ !"degenerated" = $log_file ] # please correct it then echo " ECHT " >>$work |
see the man page of grep, it will help you
|
ok i have put
find = " grep degenerated $logfile | wc -l " if [ $find >1] then echo " ECHT " >> $work but it doesnt work....... |
Hi,
Give this a try: Code:
if [ $( grep "degenerated" "$logfile" ) ] |
Explain what is not working? Also, what shell are you using?
|
more simple: grep degenerated $logfile && echo ECHT >> "$work"
---------- Post added 23rd Apr 2012 at 09:44 ---------- Quote:
|
Quote:
|
Quote:
|
| All times are GMT -5. The time now is 04:40 AM. |