sh script that reads/writes based upon contents of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sh script that reads/writes based upon contents of a file
# 1  
Old 07-11-2006
CPU & Memory sh script that reads/writes based upon contents of a file

Hi everyone,

Ive got a quick question about the feasibility and any suggestions for a shell script. I can use sh or ksh, doesnt matter. Basically, Ive got an output file from a db2 command that looks like so:

SCHEMA NAME CARD LEAF ELEAF LVLS ISIZE NDEL KEYS F4 F5 F6 F7 F8 REORG
-------------------------------------------------------------------------------------------------
Table: DB2INST2.ADVISE_INDEX
DB2INST2 IDX_I1 4 1 0 1 10 0 2 100 - - 0 0 -----
DB2INST2 IDX_I2 4 1 0 1 24 0 4 100 - - 0 0 -----
Table: DB2INST2.ADVISE_INSTANCE
SYSIBM SQL060710185042710 2 1 0 1 10 0 2 100 - - 0 0 -----
Table: DB2INST2.ADVISE_MQT
DB2INST2 MQT_I1 - - - - - - - - - - - - -----
DB2INST2 MQT_I2 - - - - - - - - - - - - -----
Table: DB2INST2.ADVISE_PARTITION
DB2INST2 PRT_I1 - - - - - - - - - - - - -----
Table: DB2INST2.Active_Server_Pages
DB2INST2 ACTSRVPG_IDX - - - - - - - - - - - - -----
Table: DB2INST2.Active_Server_Pages_D
DB2INST2 ACTSRVPG_DX 8622 127 0 3 97 0 8622 65 89 52 0 0 *----
DB2INST2 ACTSRVPG_DX2 8622 41 0 2 82 0 2889 76 90 2 0 0 *----
Table: DB2INST2.Active_Server_Pages_H
DB2INST2 ACTSRVPG_HX 20492 302 0 3 97 0 20492 7 89 22 0 0 *----



If any of you are db2 dba's, youll recognize its the output for reorgchk. Basically what im trying to do is to move the string after "Table: " to a differnt file if any of the output between it and the next occurance of "Table: " contains a star(*). Im thinking I would need to use SED to somehow extract that block of text, put it in another file, place the schema.tablename (in the last case it is DB2INST2.Active_Server_Pages_H) in a variable, grep that file for the star, and if it exists (no matter how many occurances), then write that variable that has the schema.tablename to another file enclosed in a command that I already have (will be reorg table). Any takers on the feasibility of this? Please request clarification if nessesary.
# 2  
Old 07-11-2006
try
Code:
#!/bin/ksh

awk 'BEGIN {i=-1}
{
 if($1 ~ /^Table/) { i++;}
 arr[i]=arr[i] "\n" $0;   
}
 END { for (i in arr) { if(index(arr[i],"*")>0) {print arr[i];} } }
 	 
 ' filename

# 3  
Old 07-11-2006
Code:
awk '/^Table/{table=$0; f=1 } /\*/ { if (f--) { print table }}'

# 4  
Old 07-12-2006
THANKS both of you guys! One minor adjustment I made though...specifically I need just the table name out of the line, not the entire line, so I used $2 to print to the file instead of $0...Thanks though!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script that reads a file

I have below script to read a file line by line. How can I ensure that the loop will stop after last line. #!/bin/bash while read -r mod ver tarball; do echo $mod done < taskfile.txt (4 Replies)
Discussion started by: aderamos12
4 Replies

2. Shell Programming and Scripting

File comparison based on contents

Hi I have 2 files 1.del ---- 1,2,3,4,5 1,2,3,4,4 1,1,1,1,2 2.del ---- 1,2,3,4,5 1, 1,2,3,4,4 1,1,1,1,2 I need to compare the above two files in unix, as in the output should only tell the difference in contents as I should get only the line 1 ( from 2.del) , rest all lines are... (4 Replies)
Discussion started by: Ethen561
4 Replies

3. Shell Programming and Scripting

Help with script that reads and writes java console Minecraft

Hi I am looking for an easy way to lock game mode (0) for everyone included op on a Minecraft server. It can be a script that every time a player changes game to 1 the script changes back to 0. What the player writes is visible in the java console. I am not good at script programming and my... (0 Replies)
Discussion started by: MyMorris
0 Replies

4. UNIX for Dummies Questions & Answers

Difference between buffered disk reads and cached reads?

I was analyzing the Disk read using hdparm utility. This is what i got as a result. # hdparm -t /dev/sda /dev/sda: Timing buffered disk reads: 108 MB in 3.04 seconds = 35.51 MB/sec # hdparm -T /dev/sda /dev/sda: Timing cached reads: 3496 MB in 1.99 seconds = 1756.56 MB/sec... (1 Reply)
Discussion started by: pinga123
1 Replies

5. Filesystems, Disks and Memory

Life span of HDD - maximum reads/writes etc

Hi All I was wondering how the copying of vast amounts of data affected the overall lifespan of an HDD. In my example, I'm copying approx 120GB (250,000) of files, once per hour from disk to another. Is this likely to have a detrimental effect on the disk in terms of reads/writes etc? ... (2 Replies)
Discussion started by: huskie69
2 Replies

6. Filesystems, Disks and Memory

Does vmstat -d give a count of actual physical writes/reads done to/from hard disk?

Hi, I am trying to find the reliability of 'vmstat -d' for showing the actual physical writes on sectors on hard disk. Can anyone please tell me if the numbers in the "sectors" field under "read" or "write" headers show a count of the actual write commands sent to disk from the low level... (2 Replies)
Discussion started by: jake24
2 Replies

7. Shell Programming and Scripting

Problem with Script that writes max lines of a file - Any ideas how to fix?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (4 Replies)
Discussion started by: mmiller99
4 Replies

8. UNIX for Advanced & Expert Users

identify the unix process performing high disk i/o reads and writes

Guys, Is there any UNIX command that captures the 'Unix process which is performing high disk I/O reads and writes'. can you help me in this? -Swamy (6 Replies)
Discussion started by: avsswamy
6 Replies

9. Shell Programming and Scripting

identify the unix processes performing high disk i/o reads and writes

I would like to write shell/perl script which identifies the top unix processes that are performing high disk I/O's or/and writes If any one knows the solution please help me? -Swamy (0 Replies)
Discussion started by: avsswamy
0 Replies

10. Shell Programming and Scripting

Shell script that reads from configuration file to get database

Hi intelligent beings, I am trying to write a script that 1. Accepts the following arguments: store_number div_number user_id div_code 2. Will read from a configuration file to get the Database 3. Use the div_code to determine which value to retrieve from the configuration file ... (1 Reply)
Discussion started by: dolo21taf
1 Replies
Login or Register to Ask a Question