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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing Alphabetically

Status
Not open for further replies.

jmanj

Programmer
May 20, 2003
298
US
Hello,

I have had a lot of help in this forum learning how to write a script in unix and I really appreciate your help. Now I have another challenge for me to do. The following script below works fine when I'm trying to list all active procedures running under ScanFileClient (daemon). I have no problem so far with the script I created except now I wanted the listing to be sorted by the third displayed field($10). Thanks for any help on this.

ps -ef | awk '/S[c]anFileClient/{printf "%3d) %s\t%s\t%s\t%s \n",++i,$2,$9,$10,$11}'
 
man sort (the -k option)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thanks for the quick reply. Here's the line that made it possible:

ps -ef |awk '/S[c]anFileClient/{printf "%3d) %s\t%s\t%s\t%s \n",++i,$2,$9,$10,$11}'|sort -k 4,4|lashow
 
Again I have another challenge based on the previous example. I know I have done it before but I could not remember how I did it and hoping somebody can help me out. here's the shell script again and let's call it ListScanFile.khs

ps -ef | awk '/S[c]anFileClient/{printf "%3d) %s\t%s \n",++i,$2,$10}'|sort -k 3,3|lashow

But I wanted it to be:

ps -ef | awk '/S[c]anFileClient/{printf "%3d) %s\t%s \n",++i,$2,$10}'|sort -k $1,$1|lashow

It means I want to call ListScanFile.ksh with parameter either
1 or 2 or 3... ie ListScanFile.ksh 3

Now I what I really wanted is to substitue a default value
of 1 if there was no parameter entered. something like

sort -k $1{1},$1{1}


Thanks again for any help.
 
sort -k ${1:-1},${1:-1}

BTW, man ksh

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thats was really cool! It works and now I can just display
which columns and in sorted manner. Thanks a lot...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top