Need awk help
Posted in 1999
Hello Everybody, XPS 821Ud1 on Solaris 2.5.1 I am working on one awk script. I need help in that. Following is the requirement I need to display a kind of spread sheet of following details. DBSLICE1 DBSPACE.1 CHUNK.1 SIZE(KB) DBSPCAE.2 CHUNK.2 SIZE(KB) DBSLICE2 DBSPACE2.1 CHUNK2.1 SIZE(KB) I am taking input from $INFORMIXDIR/etc/xcfg_$INFORMIXSERVER.SERVERNUM - The file detail looks like DBSlice 1 6 1 32768 rootdbs DBSlice 2 72 7 8193 tmpslc DBSlice 3 24 649 1 kd_slc DBSpace 1 1 1 98304 1 1 1 1 6 rootdbs.1 DBSpace 2 2 1 98304 6 6 1 6 -1 rootdbs.6 DBSpace 3 3 1 98304 5 5 1 5 2 rootdbs.5 Chunk 1 1 -1 524284 4 13 /ix/rootdbs.1 0 0 Chunk 2 2 -1 524284 4 13 /ix/rootdbs.6 0 0 Chunk 3 3 -1 524284 4 13 /ix/rootdbs.5 0 0 Required output should be rootdbs rootdbs.1 /ix/rootdbs.1 524284 rootdbs.6 /ix/rootdbs.6 524284 so on for all the dbslices. I made the following script #!/bin/ksh FILE=/home/dbmstech/dbit/var/xcfg_sdwp1m.1 ( ## Display a header printf "%-35s\\t%-35s\\t%-35s\\t%11s\\n" "DBSlice" "DBSpace" "Chunk" "Size" printf "---------------------------------------------------------------------------------------------------------------------------------- -\\n" cat xcfg_sdwp1m.1|awk '{ if ($1 == "DBSlice") print $4, $6 > "/tmp/sdwprod_dbslices.out" if ($1 == "DBSpace") print $2, $8, $11 > "/tmp/sdwprod_dbspaces.out" if ($1 == "Chunk") print $3, $8, $5 > "/tmp/sdwprod_chunks.out" }' cat /tmp/sdwprod_dbslices.out|sort +0 > "/tmp/dbslices_sort.out" cat /tmp/sdwprod_dbspaces.out|sort +1 > "/tmp/dbspaces_sort.out" cat /tmp/sdwprod_chunks.out|sort +0 > "/tmp/chunks_sort.out" echo ' '|nawk 'BEGIN{ ## Load the input in the array while (( getline < "/tmp/dbslices_sort.out" ) >0) { dbslice++ sdwprod_dbslices[dbslice]=$0 } while (( getline < "/tmp/dbspaces_sort.out" ) >0) { dbspace++ sdwprod_dbspaces[dbspace]=$0 } while (( getline < "/tmp/chunks_sort.out" ) >0) { chunk++ sdwprod_chunks[chunk]=$0 } } { for (dbslice in sdwprod_dbslices) { if (sdwprod_dbslices[$1] == sdwprod_dbspaces[$2] && sdwprod_dbspaces[$1] == sdwprod_chunks[$1]) { sdwprod_final[1] = sdwprod_dbslices[2] sdwprod_final[2] = sdwprod_dbspaces[3] sdwprod_final[3] = sdwprod_chunks[2] sdwprod_final[4] = sdwprod_chunks[3] } } } END { for (i in sdwprod_final) { printf ("%-35s\\t%-35s\\t%-35s\\t%11d\\n", sdwprod_final[1], sdwprod_final[2], sdwprod_final[3], sdwprod_final[4]*4) } }' $FILE ) | more This script is not giving the required output. I will highly appreciate if someone can suggest the required change or some other way in awk to do this. Thanks Sanjeev K. Sagar _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com