search for key word and execute


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search for key word and execute
# 8  
Old 04-16-2009
Quote:
Originally Posted by rider29
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
do few changes as shown
Code:
 
Args1="$1"
Args2="$2"
/u01/.././script1 >> SCRIPT1.txt
searchtext=`head -1 SCRIPT1.txt` #this will get the first line of the o/p of first script
echo "$searchtext"|grep -q "keyword" 
if [ $? -eq 0 ] ; then

/u01/../triggerScript "Arg2"
fi

# 9  
Old 04-16-2009
Code:
Args1="$1"
Args2="$2"
SCRIPT1=/u01/.././script1

$SCRIPT1 $Args1 | head -1 | grep "$Args2" > /dev/null

if [ $? -eq 0 ]; then
  /u01/../triggerScript "Arg2"
fi

BTW:

+ Provide more descriptive argument names
+ SCRIPT1 variable is probably unnecessary. Just use the name explicitly.
+ /u01/../script1 -- means the script1 is in the / root directory. The ".." is certainly odd here.

+ You had 2 ]] 's.
+ I think you meant "searchText" in your grep line.

But just edit mine...

Last edited by quirkasaurus; 04-16-2009 at 04:56 PM.. Reason: some mind reading edits...
# 10  
Old 04-16-2009
is there a way with out creating any auxiliary files in between coz this script which we write will be used by 100s of folks.I really appreciate your time and help.
# 11  
Old 04-16-2009
it's not creating any auxiliary files....

but you can use "grep -q" instead of > /dev/null
if that was your concern.
# 12  
Old 04-16-2009
thanks quirkasaurus.Sorry, I was addressing Vidhyadhar85.

Here is the corrected version, had typos in my post.

****************************************
Args1="$1" (Args1 is script specific argument that will make script1 to spit bunch of text lines )
Args2="$2"
SCRIPT1=/u01/{directory1}/{directory12}/script1
searchText="`$SCRIPT1 "$Args1"`" (Here i need to get first line from the script1 output which may have multiple text lines)

if [$searchText|grep "keyword" >/dev/null ]
then
/u01/../triggerScript "Arg2"
fi

thanks for the post
# 13  
Old 04-16-2009
check my earlier post.
use my first script.
it's optimal.
# 14  
Old 04-17-2009
Hi,
I have been getting these errors(after making changes). Please help

if[0 -eq 0]: command not found
syntax error near unexpected token `then'
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