Filtering out rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filtering out rows
# 1  
Old 03-19-2013
Filtering out rows

PHP Code:

# powermt display dev=all

.... snipped ...

Pseudo name=hdiskpower8
Symmetrix ID
=000192602584
Logical device ID
=059F
state
=alivepolicy=SymmOptpriority=0queued-IOs=0
==============================================================================
---------------- 
Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
###  HW Path                I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
   
0 fscsi0                    hdisk12   FA 10fA   active  alive      0      0
   0 fscsi0                    hdisk22   FA  8fA   active  alive      0      0
   1 fscsi1                    hdisk33   FA  7fA   active  alive      0      0
   1 fscsi1                    hdisk43   FA  9fA   active  alive      0      0

Pseudo name
=hdiskpower1
Symmetrix ID
=000192602584
Logical device ID
=05BC
state
=alivepolicy=SymmOptpriority=0queued-IOs=0
==============================================================================
---------------- 
Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
###  HW Path                I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
   
0 fscsi0                    hdisk15   FA  8fA   active  alive      0      0
   1 fscsi1                    hdisk26   FA  7fA   active  alive      0      0
   1 fscsi1                    hdisk36   FA  9fA   active  alive      0      0
   0 fscsi0                    hdisk5    FA 10fA   active  alive      0      0

.... snipped ... 
I have these outputs. Each block of the output can have 2, 3, 4 rows.
Each row must show active alive. If not, I want to entire block displayed, so I know which one has issues. If all shows active alive, then "No Issues Found" returned.

Please advise.
# 2  
Old 03-19-2013
You could try something like this:
Code:
powermt display dev=all|
awk '
  BEGIN{
    m="No Issues Found"
    FS=RS
    RS=""
  }

  {
    for(i=NF; i>NF-4; i--) {
      if($i~/==/) next
      else if($i!~/active  alive/) {
        m=$0
        exit 1
      }
    }
  } 

  END{
    print m
  }
'

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 03-19-2013
PHP Code:
 Syntax Error The source line is 10.
 The error context is
                      
>>>  if($i~/= <<< 
 
awk0602-502 The statement cannot be correctly parsedThe source line is 10.
 awk
0602-502 The statement cannot be correctly parsedThe source line is 11. 
I am getting this error. Please advise.
# 4  
Old 03-19-2013
Try:
Code:
$i~/\=\=/

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 03-19-2013
PHP Code:
powermt display dev=all|
awk '
  BEGIN{
    m="No Issues Found"
    FS=RS
    RS=""
  }

  {
    for(i=NF; i>NF-4; i--) {
      if($i~/\=\=/) next
      else if($i!~/active  alive/) {
        m=$0
        exit 1
      }
    }
  } 

  END{
    print m
  }

It fixed the syntax error, but it seems this script only scans the first block and doesn't scan the following blocks. There are many of blocks like shown above.
Please advise.
# 6  
Old 03-19-2013
You could make a quick adaptation of the script by leaving out the exit 1 return code and instead of:
Code:
m=$0
exit 1

Use
Code:
m=""
print
next

This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 03-19-2013
Yes! It works perfect!
Appreciate it!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving or copying first rows and last rows into another file

Hi I would like to move the first 1000 rows of my file into an output file and then move the last 1000 rows into another output file. Any help would be great Thanks (6 Replies)
Discussion started by: kylle345
6 Replies

2. Shell Programming and Scripting

Merging rows using two common rows.

Hi.. My requirement is simple but unable to get that.. File 1 : 3 415 A G 4 421 G . 39 421 G A 2 421 G A,C 41 427 A . 4 427 A C 42 436 G . 3 436 G C 43 445 C . 2 445 C T 41 447 A . Output (4 Replies)
Discussion started by: empyrean
4 Replies

3. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

4. Shell Programming and Scripting

filtering the rows in a file

hi all, please help on this isssue, i have a file which contains something like this and i want to seprate the servers which has vasd.pid ,i need only server names. i want output something like this which vasd.pid . server1 server3 server4 (4 Replies)
Discussion started by: sudharson
4 Replies

5. Shell Programming and Scripting

Split single rows to multiple rows ..

Hi pls help me out to short out this problem rm PAB113_011.out rm: PAB113_011.out: override protection 644 (yes/no)? n If i give y it remove the file. But i added the rm command as a part of ksh file and i tried to remove the file. Its not removing and the the file prompting as... (7 Replies)
Discussion started by: sri_aue
7 Replies

6. Shell Programming and Scripting

Remove 1st two rows and last 2 rows

Hi All, I need to remove 1st 2 line from head and last 2 line from last. I thought it would be possible by using the Head and tail command. But after i am using it is not possible by it. Example:Input file 1 2 3 4 5 Example: Output file 3 But my head and tail command are not... (12 Replies)
Discussion started by: kam786sim
12 Replies

7. Shell Programming and Scripting

Filtering rows for first two instances of a value

Kindly help me with this problem: My data looks like this: SNPfile.txt CHR_A BP_A SNP_A CHR_B BP_B SNP_B R2 p-SNP_A p-SNP_B 4 172575323 rs17056855 4 172601079 rs11945883 0.119414 0.049972656 0.031050345 4 172575323 rs17056855 4 ... (2 Replies)
Discussion started by: genehunter
2 Replies

8. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies

9. UNIX for Dummies Questions & Answers

Converting rows into multiple-rows

Hi every one; I have a file with 22 rows and 13 columns which includes floating numbers. I want to parse the file so that every five columns in the row would be a new record (row). For example, the first line in the old file should be converted into three lines with first two lines contain 5... (6 Replies)
Discussion started by: PHL
6 Replies

10. Shell Programming and Scripting

Command filtering ONLY rows NOT beginning with '*'

I need a command which filters rows ONLY NOT beginning with '*' So far I have following NOT sufficient command, because it does not include ALL possible literals except of '*' grep ^ INPUT_FILE >>OUTPUT_FILE Is it possible to write something like grep NOT ^ INPUT_FILE... (3 Replies)
Discussion started by: ABE2202
3 Replies
Login or Register to Ask a Question