Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get one specfic word from each line and check that process

Status
Not open for further replies.
Feb 6, 2003
7
US
Hello,
I have following input file
BIP8099I: UserNameServer - MQSUA02
BIP8099I: MQSUA02 - MQSUA02
BIP8099I: MQSTA01 - MQSTA01
BIP8099I: MQSUA04 - MQSUA04
BIP8099I: MQSUA99 - MQSUA99
BIP8099I: MQSSA02 - MQSSA02
BIP8099I: MQSTA04 - MQSTA04
BIP8099I: MQSSA04 - MQSSA04
BIP8071I: Successful command completion.
what I want is to get word "UserNameServer" ,"MQSUA02" ...
I mean I want to read Second Column and check each process status ex. "ps -ef | grep MQSUA02" so please help me to write this code
Thank you,
vikas
 
You could just use :
for linesn in `grep "UserNameServer" infile|cut -c30-40`
do
ps -ef|grep $linesn
done

- if all fields are always in those positions in your input file.

Dickie Bird (:)-)))
 
I have one problem I can't use "MQSUA02" or MQSTA01 etc etc
coz this file get generated by some application program so I want to know the way to read all words from second column and check with ps -ef coz I am not sure what it's going to write in this file and one good thing is this is fix format so I am just worry about second column variables
Please help me to resolve this issue
Thankx
vikas
 
I don't fully understand your requirements.
Do all the lines in which you're interested begin with :
BIP8099I: MQ ?
If so, grep for that, and cut -c11-17
HTH
Dickie Bird (:)-)))
 
hey Dickie
here is my complete requirement
I am writing this code to start the wmqi compoents using shell and awk.
I have input file that list my all components as shown above now in my second column I have all components name
UserNameServer, MQSTA01, etc so I need to only get this second column and check each compoent with ps -ef you know what I mean for example ( ps -ef | grep MQSTA04 ) so I have to read each line and get the second column and check the status and my another req is from my input file I want to delete last line "BIP8071I: Successful command completion" I don't want this last line in my input file so could you help me to resolve this issue
Thanks for your help
vikas

 
To remove the last line of any file :

sed '$d' infile > new-file


HTH
Dickie Bird (:)-)))
 
if i want grep "UserNameServer" from first line then what should i do coz cut11-17 only give me "UserNam" not the complete word "UserNameServer"

Thanks,
vikas
 

Code:
for linesn in `grep "UserNameServer" infile|awk '{print $NF}'`
do
  echo "checking for $linesn"
  ps -ef|grep $linesn 
done


Its the same as dickiebird suggested except for 'cut' replaced with 'awk'.

if you want to do 'ps -ef....' for all lines (whether or not they contain UserNameServer) try


Code:
for linesn in `grep -v "Successful command completion" infile |awk '{print $NF}'`
do
  echo "checking for $linesn"
  ps -ef|grep $linesn
done


I am not very sure which column you want so I've put $NF for the last column. You can replace it with the column number you want.

Hope that helps.

Cheers,
Pravin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top