search for key word and execute


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search for key word and execute
# 1  
Old 04-16-2009
search for key word and execute

Hi,

I am writing a shell (after 6-7 months)that has to receive text from another shell, check if the first line in the text has a key word and then execute different shell.I could come up with the below program structure, please suggest me if there is a better way to do it or please help me with this script.

More deatails:

Have script1, arg1, Myscript (to be writen), triggerScript

*********
# MyScript, should check for keyword inside the text output from script1 and execute triggerScript

arg1="$1"
script1=/./../script

searchText="`$script1 "arg1"`" (Need to get first line of the text out from script1.)

if [ grep for "Keyword" in $searchText && exists/True] ]
then
./tiggerScript (execute trigger script)
fi
********

Last edited by rider29; 04-16-2009 at 02:17 PM..
# 2  
Old 04-16-2009
so you wanna search the keyword in the o/p of the script??
then redirect the o/p of the script to a variable or to a file(to be safe and more specific result) then grep for that word and rest is as you written
# 3  
Old 04-16-2009
yes i want to search for a keyword. My intention was same but I keep getting errors. So was looking for help
# 4  
Old 04-16-2009
Quote:
Originally Posted by rider29
yes i want to search for a keyword. My intention was same but I keep getting errors. So was looking for help
what and where you are getting errors??
# 5  
Old 04-16-2009
My trigger script was not getting executed even though I have a key word, If condition is not proper i guess. Plz suggest a generic If condition for my block of code.
# 6  
Old 04-16-2009
can you post the exact code of yours??
Code:
grep -q "keyword" $search
if [ $? -eq 0 ] ; then
call your script here
fi

# 7  
Old 04-16-2009
this what I wrote, forgive me if there are blunders :-)

Args1="$1"
Args2="$2"
SCRIPT1=/u01/.././script1
searchText="`$SCRIPT1 "$Args1"`" (Here i need to get first line from the script1 output which may have multiple text lines)

if [$searchTest|grep "keyword" >/dev/null] ]
then
/u01/../triggerScript "Arg2"
fi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies

3. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

4. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

5. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Discussion started by: sachit adhikari
4 Replies

6. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script?

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word description excluding weird characters like $$#$#@$#@***$# and without html tags in the new file output.txt. Help me. Thanx in advance. My final goal is to... (11 Replies)
Discussion started by: sachit adhikari
11 Replies

7. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

8. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

9. Shell Programming and Scripting

perl (word by word check if a hash key)

Hi, Now i work in a code that 1-get data stored in the database in the form of hash table with a key field which is the " Name" 2-in the same time i open a txt file and loop through it word by word 3- which i have a problem in is that : I need to loop word by word and check if it is a... (0 Replies)
Discussion started by: eng_shimaa
0 Replies

10. Shell Programming and Scripting

Help adding a key word search to my script

Hello: I need help adding a key word search to my bash script. I have the following script. My boss whats the user to be able to add a search word e.g. unknown failures for the script to search the logs through and find the instances. I had originally done it so it grepped for unknown... (8 Replies)
Discussion started by: taekwondo
8 Replies
Login or Register to Ask a Question