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

How do I get the hdisks into an array without the first two fields? 1

Status
Not open for further replies.
Dec 12, 2007
19
US
If I have a record like the one shown below, how do I get the hdisk values into an array without the DISKBURY and Disk %Busy edwasu values? I am thinking that I could pipe the record to sed and replace the blanks with _ and then pipe that to sed and change the commas to blanks and have this be the result for an array but how do I avoid picking up the first two field values of DISKBUSY and Disk_%Busy_edwasu? Please keep in mind that the second field value will change depending on the server I run this script on. Thanks in advance.

DISKBUSY,Disk %Busy edwasu,hdisk0,hdisk1,hdisk2,hdisk3,hdisk69,hdisk76,hdisk11,hdisk52,hdisk79,hdisk68,hdisk77,hdisk70,hdisk53,hdisk7,hdisk6,hdisk110,hdisk13,hdisk14,hdisk15,hdisk12,hdisk17,hdisk74,hdisk21,
hdisk20,hdisk23,hdisk73,hdisk85,hdisk86,hdisk89,hdisk87,hdisk90,hdisk41,hdisk95,hdisk88,hdisk91,hdisk97,hdisk98,hdisk4,hdisk92,hdisk42,hdisk5,hdisk18,hdisk67,hdisk43,hdisk78,hdisk104,hdisk44,hdisk16,hdisk10
0,hdisk8,hdisk56,hdisk84,hdisk94,hdisk55,hdisk19,hdisk29,hdisk38,hdisk57,hdisk58,hdisk34,hdisk59,hdisk60,hdisk39,hdisk65,hdisk36,hdisk51,hdisk62,hdisk83,hdisk40,hdisk63,hdisk107,hdisk64,hdisk30,hdisk22,hdis
k45,hdisk66,hdisk61,hdisk32,hdisk103,hdisk10,hdisk50,hdisk9
 
What shell are you using?

Is that record in a file or a variable?

Is it all on one line, or two (hard to tell because of the way the text is wrapped)?

If it is all on one line something like this should work in Korn shell:

Code:
#!/usr/bin/ksh

# set the array
set -A diskarray $(sed 's/.*Busy //;s/,/ /g' /file/containing/record)

# display the contents, just for fun
i=0
while (( i < ${#diskarray[*]} ))
do
        echo diskarray[$i] = ${diskarray[$i]}
        (( i=i+1 ))
done

Annihilannic.
 
Thank you very much. This got me on track. I am using KORN shell scripts and the information is on one line. It was in a file that I had read into a variable called $line and so I was able to use this statement to accomplish what was needed.

set -A diskarray $(echo ${line} | sed 's/.*Busy //;s/,/ /g')

Thank you so very much.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top