Running awk and while loop on data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running awk and while loop on data
# 1  
Old 05-14-2013
Running awk and while loop on data

so this is what i want to do. i have data that looks like this:

DATA:

Code:
Array: A
      Interface Type: SAS
      Unused Space: 0 MB
      Status: Failed
      Logical Drive: 2
         Size: 279.4 GB
         Fault Tolerance: RAID 1
         Heads: 255
         Sectors Per Track: 32
         Cylinders: 65535
         Stripe Size: 128 KB
         Status: Interim Recovery Mode
         Array Accelerator: Enabled
         Unique Identifier: afafafaf
         Disk Name: /dev/cciss/c0d1
         Mount Points: None
         Logical Drive Label: faffafaf
         Mirror Group 0:
            physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 300 GB, OK)
         Mirror Group 1:
            physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 300 GB, Failed)
      physicaldrive 1I:1:3
         Port: 1I
         Box: 1
         Bay: 3
         Status: OK
         Drive Type: Data Drive
         Interface Type: SAS
         Size: 300 GB
         Rotational Speed: 10000
         Firmware Revision: HPDC
         Serial Number: fafafafa
         Model: HP      fafafaf
         PHY Count: 2
         PHY Transfer Rate: Unknown, Unknown
      physicaldrive 1I:1:4

   Array: B
      Interface Type: SAS
      Unused Space: 0 MB
      Status: Failed
      Logical Drive: 2
         Size: 279.4 GB
         Fault Tolerance: RAID 1
         Heads: 255
         Sectors Per Track: 32
         Cylinders: 65535
         Stripe Size: 128 KB
         Status: Interim Recovery Mode
         Array Accelerator: Enabled
         Unique Identifier: 
         Disk Name: /dev/cciss/c0d1
         Mount Points: None
         Logical Drive Label: 
         Mirror Group 0:
            physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 300 GB, OK)
         Mirror Group 1:
            physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 300 GB, Failed)
      physicaldrive 1I:1:3
         Port: 1I
         Box: 1
         Bay: 3
         Status: OK
         Drive Type: Data Drive
         Interface Type: SAS
         Size: 300 GB
         Rotational Speed: 10000
         Firmware Revision: HPDC
         Serial Number: 
         Model: HP      
         PHY Count: 2
         PHY Transfer Rate: Unknown, Unknown
      physicaldrive 1I:1:4


The actual data is of course much bigger than this. But the above is the layout. What i want to do is grab certain values under each Array.

So for Array B, say i want to grab the value of "Sectors Per Track", how do i do so? in this case, i'd like an output similar to: ArrayB=(Sectors Per Track,32).

My first instinct is to run a while loop on the command that produces the data. but i'm not sure of how to make the while loop smart enough to know when each Array begins and when it ends.

I'm hoping awk can be used here.

The ultimate goal here is to be able to grep for certain things under each array and be able to tie thing being grepped for back to the array, as i bolded above.

Another example, for Array A, see if there are any strings that contain the word "Fail". If there are, output the lines. ex. ArrayA=(physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 300 GB, Failed)

OS: Linux/SunOS
Bash
# 2  
Old 05-14-2013
Use the awk pattern
Code:
$1 ~ /^Array:/

This delimits the "array" data.
# 3  
Old 05-14-2013
i think i need something more.

i tried:
Code:
while read line

do

echo $line
awk '$1 ~ /Array:/' 

done < data.txt.

but it only gives me:
Code:
   Array: A
   Array: B
   Array: C
Smart Array P410i in Slot 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running in a loop in UNIX

I have a table in oracle which has 2 columns table_name table_name1 U1 T1 U2 T2 I have to take these as a variable in unix and then go to /home/bin and execute a unix command using these variables. Considering that there is only one row in the table I was able to write the below but need help... (2 Replies)
Discussion started by: Ashcalin
2 Replies

2. Shell Programming and Scripting

While loop is running only for the first iteration

Hello, I've written a script to automate encoding of all the MP4 files in a directory (incl. subdirectories). But unfortunately it's running for the first MP4 file only. My machine details: root@Ubuntu16:~# uname -a Linux Ubuntu16 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48... (2 Replies)
Discussion started by: prvnrk
2 Replies

3. Shell Programming and Scripting

Need help in awk: running a loop with one column and segregate data 4 each uniq value in that field

Hi All, I have a file like this(having 2 column). Column 1: like a,b,c.... Column 2: having numbers. I want to segregate those numbers based on column 1. Example: file. a 5 b 9 b 620 a 710 b 230 a 330 b 1910 (4 Replies)
Discussion started by: Raza Ali
4 Replies

4. Shell Programming and Scripting

Graphing data with awk/while loop

I need to graph data that's in a file. however, i only know of a way to graph data as it comes (meaning, as it is spat out by whatever process or job). i dont know how to graph data in a file. im using rrdtool to graph data. and i was wondering if anyone know of a way to pass a file (the... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. Shell Programming and Scripting

While Loop not running

echo "The recreate was successfully completed for device file $LCL_CLN_FILE." >> $LOG_FILE remaining=$(symclone -sid $LCL_SID -f $ETC/$LCL_CLN_FILE query | grep MB | awk '{print $2}') if then while do echo "$remaining MB's to be copied........." >> $LOG_FILE ... (10 Replies)
Discussion started by: rajsan
10 Replies

6. Shell Programming and Scripting

Help Running Loop Script

Hi I have a file called lastlogin_1 that contains a list of usernames. I would like to put together a quick loop script that will use a variable (the contents of lastlogin_1 file) and grep all directories and sub directories in the current directory (/in/the/current/directory) for each username... (3 Replies)
Discussion started by: jamba1
3 Replies

7. Shell Programming and Scripting

For loop and running 2 commands at once?

HI. I am trying to run 2 commands, using the "for x in a b c d" loop but i am having a hard time coding it... Here is what i have so far: for SERVER in SERVERA SERVERB SERVERC SERVERD SERVERE do ############################################################################### #... (5 Replies)
Discussion started by: Stephan
5 Replies

8. Shell Programming and Scripting

loop when process running

Hi Gurus, Could you please help me to create a shell script that will be started by a cron job once every night at 24.00 h (that should bee easy:)) The shell script should control every 30 seconds the name of a process, and when the process doesn't run anymore it should execute a few further... (12 Replies)
Discussion started by: blackwire
12 Replies

9. Shell Programming and Scripting

running command in while loop

I have a script that users a while read, whithin this I want to execute the cp -i command on some of the results, however because it is in a loop it skips the -i part of cp. How do I get the loop to stop each time cp -i is run and wait for the user to type the response. (2 Replies)
Discussion started by: gefa
2 Replies

10. Shell Programming and Scripting

Using loop reading a file,retrieving data from data base.

Hi All, I am having trouble through, I am reading the input from tab delimited file containing several records, e.g. line1 field1 field2 field3 so on.. line2 field1 field2 field3 so on.. .. .. on the basis of certain fields for each record in input file, I have to retrieve... (1 Reply)
Discussion started by: Sonu4lov
1 Replies
Login or Register to Ask a Question