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!

How to make a table using awk

Status
Not open for further replies.

lotamoka

MIS
Jul 15, 2007
43
US
I have following files ...
$ cat drive17_status
Drive17
======
Jul 11 tsm03 BW5450
Jul 11 tsm03 BW4538
$ cat drive7_status
Drive7
======
Jul 13 tsm03 BR3364
Jul 13 tsm05 BR1989
$ cat drive6_status
Drive6
======
Jul 13 tsm01 BR3363
Jul 13 tsm05 BR1990
$cat drive8_status
$
And output should look like ...
$cat drive_status
Drive6 Drive7 Drive17 Drive8_status
====== ======== ======== ======
Jul 13 tsm01 BR3363 Jul 13 tsm03 BR3364 Jul 11 tsm03 BW5450
Jul 13 tsm05 BR1990 Jul 13 tsm05 BR1989 Jul 11 tsm03 BW4538
Any help appreciated ?
 
Hi

Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

* [navy]Thank Annihilannic
for this valuable post![/navy]


at the bottom of Annihilannic's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
 
Now my script is complete
Could you, please, post your final script fot the benefit of the members ?
 
This script used in TSM ( Tivoli storage manager ) system.

#!/bin/ksh
cd /home/bradmin/anil
id=`cat sysop_pw|awk '{print $1 }'`
pw=`cat sysop_pw|awk '{print $2 }'`

while read server
do
dsmadmc -se=$server -id=$id -pa=$pw -dataonly=yes q ac begind=-1 se=ANR8359E > log
got=$(grep -c detected log)
if [ $got -gt 0 ]
then
cat log|awk '/detected/{volume=$10} /drive/{drive=$2} /drive/ {print drive " " volume}' > voldrv
while read drive volume
do
date "+%b %e" | read date1

if [ $drive = DRIVE1 ]
then
echo "$date1 $server $volume" >> adrive1_status
fi

if [ $drive = DRIVE2 ]
then
echo "$date1 $server $volume" >> adrive2_status
fi
if [ $drive = DRIVE3 ]
then
echo "$date1 $server $volume" >> adrive3_status
fi
if [ $drive = DRIVE4 ]
then
echo "$date1 $server $volume" >> adrive4_status
fi
if [ $drive = DRIVE5 ]
then
echo "$date1 $server $volume" >> adrive5_status
fi
if [ $drive = DRIVE6 ]
then
echo "$date1 $server $volume" >> edrive6_status
fi
if [ $drive = DRIVE7 ]
then
echo "$date1 $server $volume" >> bdrive7_status
fi
if [ $drive = DRIVE8 ]
then
echo "$date1 $server $volume" >> bdrive8_status
fi
if [ $drive = DRIVE9 ]
then
echo "$date1 $server $volume" >> bdrive9_status
fi
if [ $drive = DRIVE10 ]
then
echo "$date1 $server $volume" >> bdrive10_status
fi
if [ $drive = DRIVE11 ]
then
echo "$date1 $server $volume" >> bdrive11_status
fi
if [ $drive = DRIVE12 ]
then
echo "$date1 $server $volume" >> edrive12_status
fi
if [ $drive = DRIVE13 ]
then
echo "$date1 $server $volume" >> cdrive13_status
fi
if [ $drive = DRIVE14 ]
then
echo "$date1 $server $volume" >> cdrive14_status
fi
if [ $drive = DRIVE15 ]
then
echo "$date1 $server $volume" >> cdrive15_status
fi
if [ $drive = DRIVE16 ]
then
echo "$date1 $server $volume" >> cdrive16_status
fi
if [ $drive = DRIVE17 ]
then
echo "$date1 $server $volume" >> cdrive17_status
fi
if [ $drive = DRIVE18 ]
then
echo "$date1 $server $volume" >> edrive18_status
fi
if [ $drive = LTO4_D1 ]
then
echo "$date1 $server $volume" >> dLTO4_D1_status
fi
if [ $drive = LTO4_D2 ]
then
echo "$date1 $server $volume" >> dLTO4_D2_status
fi
if [ $drive = LTO4_D3 ]
then
echo "$date1 $server $volume" >> dLTO4_D3_status
fi
if [ $drive = LTO4_D4 ]
then
echo "$date1 $server $volume" >> dLTO4_D4_status
fi
if [ $drive = LTO4_D5 ]
then
echo "$date1 $server $volume" >> dLTO4_D5_status
fi
if [ $drive = LTO4_D6 ]
then
echo "$date1 $server $volume" >> eLTO4_D6_status
fi

done < voldrv
fi

done < tsmserver
ln=1
for drives in `ls -l *_status|awk '{print $9}'`
do
newln=`cat $drives|wc -l`
if [ $newln -gt $ln ]
then
ln=$newln
fi
done
(( LINES = $ln + 1 ))

awk -v lines=$LINES '
BEGIN {

# for each filename argument
for (f=1; f<ARGC; f++) {
# for each line of report output
for (l=1; l<lines; l++) {
if (getline < ARGV[f]) {
line[l]=sprintf("%s%-25s",line[l],$0)
} else {
if (l==1) {
# first line empty, print filename
line[l]=sprintf("%s%-25s",line[l],ARGV[f])
} else {
# add empty column
line[l]=sprintf("%s%-25s",line[l]," ")
}
}
}
close(ARGV[f])
}
# print the report
for (i=1; i<=lines; i++) { print line }
}
' adrive*_status > drive_stat1


awk -v lines=$LINES '
BEGIN {
# for each filename argument
for (f=1; f<ARGC; f++) {
# for each line of report output
for (l=1; l<lines; l++) {
if (getline < ARGV[f]) {
line[l]=sprintf("%s%-25s",line[l],$0)
} else {
if (l==1) {
# first line empty, print filename
line[l]=sprintf("%s%-25s",line[l],ARGV[f])
} else {
# add empty column
line[l]=sprintf("%s%-25s",line[l]," ")
}
}
}
close(ARGV[f])
}
# print the report
for (i=1; i<=lines; i++) { print line }
}
' bdrive*_status > drive_stat2
awk -v lines=$LINES '
BEGIN {
# for each filename argument
for (f=1; f<ARGC; f++) {
# for each line of report output
for (l=1; l<lines; l++) {
if (getline < ARGV[f]) {
line[l]=sprintf("%s%-25s",line[l],$0)
} else {
if (l==1) {
# first line empty, print filename
line[l]=sprintf("%s%-25s",line[l],ARGV[f])
} else {
# add empty column
line[l]=sprintf("%s%-25s",line[l]," ")
}
}
}
close(ARGV[f])
}
# print the report
for (i=1; i<=lines; i++) { print line }
}
' cdrive*_status > drive_stat3


awk -v lines=$LINES '
BEGIN {
# for each filename argument
for (f=1; f<ARGC; f++) {
# for each line of report output
for (l=1; l<lines; l++) {
if (getline < ARGV[f]) {
line[l]=sprintf("%s%-25s",line[l],$0)
} else {
if (l==1) {
# first line empty, print filename
line[l]=sprintf("%s%-25s",line[l],ARGV[f])
} else {
# add empty column
line[l]=sprintf("%s%-25s",line[l]," ")
}
}
}
close(ARGV[f])
}
# print the report
for (i=1; i<=lines; i++) { print line }
}
' dLTO4_D*_status > drive_stat4
awk -v lines=$LINES '
BEGIN {
# for each filename argument
for (f=1; f<ARGC; f++) {
# for each line of report output
for (l=1; l<lines; l++) {
if (getline < ARGV[f]) {
line[l]=sprintf("%s%-25s",line[l],$0)
} else {
if (l==1) {
# first line empty, print filename
line[l]=sprintf("%s%-25s",line[l],ARGV[f])
} else {
# add empty column
line[l]=sprintf("%s%-25s",line[l]," ")
}
}
}
close(ARGV[f])
}
# print the report
for (i=1; i<=lines; i++) { print line }
}
' e*_status > drive_stat5



cat drive_stat1 > drive_tatus
echo "====================================================================================================================================== " >> drive_tatus
cat drive_stat2 >> drive_tatus
echo "====================================================================================================================================== " >> drive_tatus
cat drive_stat3 >> drive_tatus
echo "====================================================================================================================================== " >> drive_tatus
cat drive_stat4 >> drive_tatus
echo "====================================================================================================================================== " >> drive_tatus
cat drive_stat5 >> drive_tatus
echo "====================================================================================================================================== " >> drive_tatus

cat drive_tatus |mail -s "Tape and drive status in Bridgewater TSM tape Library." email_address1,email_address2
exit 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top