If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > search a word

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-04, 08:15
pooja pooja is offline
Registered User
 
Join Date: Dec 2002
Posts: 104
search a word

Hello All,

I wud like to know how can i grep a word in a file.
For example : like to find 87 ....

so result shud give me 87 ..not 1487 or 98771.

Also, Please tell me a way to find out the completion of background processes.

Any help wud be appreciated.

thanx in advance

--Pooja
Reply With Quote
  #2 (permalink)  
Old 01-21-04, 12:08
sushant sushant is offline
Registered User
 
Join Date: Jan 2004
Posts: 49
Re: search a word

try using -w option
e.g. grep -w 87 filename

sushant
Reply With Quote
  #3 (permalink)  
Old 01-21-04, 13:23
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
Re: search a word

Completion on background process ...

pooja, Can you elaborate a bit on what you need

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #4 (permalink)  
Old 01-21-04, 22:15
pooja pooja is offline
Registered User
 
Join Date: Dec 2002
Posts: 104
Re: search a word

Quote:
Originally posted by sathyaram_s
Completion on background process ...

pooja, Can you elaborate a bit on what you need

Cheers
Sathyaram
Hello Sathyaram,

My requirement is, i am sending something for background processing and dependent on its completion i wud like to proceed further.

At present what i am doing is , i am taking the process ids of background processes intiated in a file .Then using this command,

var=ps -ef | egrep -c -f <file which contains process ids for background proceses>

and checking till var != 0
(I am sure there will be much better ways to do this.)

Here i am facing a problem,

egrep is doing a pattern searching , i want to find full word not the part of word.

Also, if there is better way to do this , please tell me

thanx in advance.

--Pooja
Reply With Quote
  #5 (permalink)  
Old 01-21-04, 22:16
pooja pooja is offline
Registered User
 
Join Date: Dec 2002
Posts: 104
Re: search a word

Quote:
Originally posted by sushant
try using -w option
e.g. grep -w 87 filename

sushant
Hi sushant,

thanx, its working

--Pooja

Last edited by pooja; 01-21-04 at 22:18.
Reply With Quote
  #6 (permalink)  
Old 01-22-04, 04:53
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Re: search a word

Quote:
Originally posted by pooja

Also, Please tell me a way to find out the completion of background processes.
Use the 'wait' command. You can give it a pid but it's esier to use the job id.

e.g.

sleep 5 &
wait 1
echo Done waiting

HTH
Reply With Quote
  #7 (permalink)  
Old 01-22-04, 23:25
pooja pooja is offline
Registered User
 
Join Date: Dec 2002
Posts: 104
Re: search a word

Quote:
Originally posted by Damian Ibbotson
Use the 'wait' command. You can give it a pid but it's esier to use the job id.

e.g.

sleep 5 &
wait 1
echo Done waiting

HTH
thanx

but i am sending 10 jobs in background .Please advice .

--Pooja
Reply With Quote
  #8 (permalink)  
Old 01-27-04, 06:15
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Re: search a word

Quote:
Originally posted by pooja

but i am sending 10 jobs in background .Please advice .
If you were to use 'wait' in this instance, I would suggest using the pid rather than the job id. Get the pid using ps + awk/sed/grep/cut (or whatever).

That said, if it's going to get complicated, I would have each background process write to a file on completion and have a daemon/loop to check that file for the status of each background process before kicking off the next process.
Reply With Quote
  #9 (permalink)  
Old 01-27-04, 08:40
pooja pooja is offline
Registered User
 
Join Date: Dec 2002
Posts: 104
Re: search a word

Quote:
Originally posted by Damian Ibbotson
If you were to use 'wait' in this instance, I would suggest using the pid rather than the job id. Get the pid using ps + awk/sed/grep/cut (or whatever).

That said, if it's going to get complicated, I would have each background process write to a file on completion and have a daemon/loop to check that file for the status of each background process before kicking off the next process.
thanx,

at present what i am doing is, i am writing the PID into a file when i send a job in background and after sending all the required jobs in background i am checking the system if any PID exists there, for this i am using a while loop
while var>0
do
var=ps-ef -o pid | grep -cw -f filewithpid
wait 60
done


--Pooja
Reply With Quote
  #10 (permalink)  
Old 01-27-04, 08:49
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Hi Pooja.

I'm not sure what the 'wait 60' is doing, I think you mean 'sleep 60'.

The only problem I can see with how you have implemented your solution would be if one of your processes failed. The pid would no longer exist, so your dependent process would kick-off!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On