Finding a "word" through grep but display line above?

Hi guys.

I am trying to perform a search using grep. I get my grep to work, but need to "awk" a Process Number that is 2 lines above...

Example:

I run a query on my TSM server for Processes that are "Waiting" for something...it returns this:

 Process Number: 32,881

Process Description: Space Reclamation
Status: Offsite Volume(s) (storage pool T950_VAULT_OTHERDB), Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 2,413,746 Waiting for mount of input volume 210674L4 (4 seconds). Waiting for mount of scratch volume (4 seconds).

If i "grep" the word "Waiting", all i get is this:

Status: Offsite Volume(s) (storage pool T950_VAULT_OTHERDB), Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 2,413,746 Waiting for mount of input volume 210674L4 (4 seconds). Waiting for mount of scratch volume (4 seconds).

How would get my return to show me the above 2 lines, especially the one about the process number, so that i can awk it out?

Thanks.

Should we understand the "status" line finishes at dot after 4 seconds) ?

So you would have 3 lines and you want the first and last?

Is your TSM server an AIX?

---------- Post updated at 16:04 ---------- Previous update was at 15:53 ----------

e.g.

ian1:/home/vbe $ oslevel
6.1.0.0
ian1:/home/vbe $ cat sample_test.file
Process Number: 32,881
Process Description: Space Reclamation
Status: Offsite Volume(s) (storage pool T950_VAULT_OTHERDB), Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 2,413,746 Waiting for mount of input volume 210674L4 (4 seconds). Waiting for mount of scratch volume (4 seconds).

ian1:/home/vbe $ grep -e "Process Number" -e Waiting sample_test.file
Process Number: 32,881
Status: Offsite Volume(s) (storage pool T950_VAULT_OTHERDB), Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 2,413,746 Waiting for mount of input volume 210674L4 (4 seconds). Waiting for mount of scratch volume (4 seconds).
ian1:/home/vbe $ 

Hi.
Yep, the "status" line finishes at the dot...

Ok, if i issue your command...I get all processes runnning including the "Waiting" ones...

q proc | grep -e "Process Number" -e Waiting
Process Number: 25,823
Process Number: 32,660
Process Number: 32,706
Process Number: 32,901
Status: Volume 701827 (storage pool TAPEUNIX_DB), Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 282,139,213 Waiting for mount of input volume 701827 (456 seconds). Current output volume: 210214L4.
Process Number: 32,902
Status: Volume 700740 (storage pool TAPEUNIX_DB), Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 62,175,904,037 Waiting for mount of input volume 700740 (456 seconds). Current output volume: 210318L4.

What if i only wanted the processes that contain the "status" waiting?

Thanks again.

You would have to give a sample a bit longer of your query in order to see what is going on and what can be done e.g. Is the output sequence: Process Number,Process Description,Status ?

The output of a "query process" within TSM is this:

     Process Number: 25,823
Process Description: GENERATE BACKUPSET
             Status: 0 of 1 backup sets have completed for a total of 0 objects and 0 bytes, with 0 objects skipped.  Of these, 0 backup sets have failed.
                      Currently generating backup set QC90990FS01_20100920.1265734289 for node QC90990FS01 (data type File).  For this backup set, there
                      have been 12,246,613 objects inspected, 4,863,241 objects and 2,193,561,619,682 bytes written, and 0 objects skipped.

     Process Number: 32,660
Process Description: Migration
             Status: Disk Storage Pool DISKNT_COMMON, Moved Files: 29372, Moved Bytes: 217,483,837,440, Unreadable Files: 0, Unreadable Bytes: 0. Current
                      Physical File (bytes): 11,390,705,664 Current output volume: 210551L4.

     Process Number: 32,706
Process Description: Expiration
             Status: Examined 5508625 objects, deleting 436691 backup objects, 2121 archive objects, 0 DB backup volumes, 0 recovery plan files; 0 errors
                      encountered.

     Process Number: 32,901
Process Description: Space Reclamation
             Status: Volume 701827 (storage pool TAPEUNIX_DB), Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical
                      File (bytes): 282,139,213 Waiting for mount of input volume 701827 (1148 seconds). Current output volume: 210214L4.

     Process Number: 32,902
Process Description: Space Reclamation
             Status: Volume 700740 (storage pool TAPEUNIX_DB), Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical
                      File (bytes): 62,175,904,037 Waiting for mount of input volume 700740 (1148 seconds). Current output volume: 210318L4.

It prints out 3 lines, as you mentionned (Process Number, Proces Desc and Status)

What i am trying to get out is the process that is Waiting for a volume...for example the process 32901 and in this case 32902 as well...

Try:

sed -n '/^Process Number/{N;N;N;s/^Process Number:[ \t]*\([0-9,]*\).*Waiting for mount.*/\1/p}' infile

output:

32,901
32,902

I get a "cannot be parsed".

I would do this?

q proc | sed -n '/^Process Number/{N;N;N;s/^Process Number:[ \t]*\([0-9,]*\).Waiting for mount./\1/p}'

??

Sorry about the naivety of the question, but this is out of my league...:slight_smile: Just started using grep and awk...now sed?

use Perl to get the paragraph which contains the word "Waiting" ...

perl -00 -wne 'print if /Waiting/' infile.txt

:slight_smile:

I would do that, yes, if q proc produces output like you described above...

awk '/^Process /{x=(x)?x FS$0:$0}/Waiting/{print x}!NF{x=z}' infile

Try:

awk '/Waiting/{print $3}' RS= file

Hehehe Franklin52, of course :b:

Look nice but what about the OP requirement?

AH! now this "almost" works...

If i use my test file it works, but when i plug this into my "q proc" query, i only get the second line returned... (Process Description).

What i noticed though, is that my test file (test.out) contains the same data but all 3 lines (Procress Number, Description and Status) start at character 0. Meaning on the far left side. but if i issue a "q proc" to test it in my real environment, the Process Number starts indented about 5 characters compared to the Process Description...

Kinda like this:

q proc | awk '/^Process /{x=(x)?x FS$0:$0}/Waiting/{print x}!NF{x=z}'

^^Process Number: 23823
Process Description: Space Reclamation
^^^^^^^^Status: blahblahblah
(^^^ are actually spaces...can't seem to get this post to insert spacing at the beginning...)

I get this in return:

Process Description: Space Reclamation

Could it be because that first line is indented?

---------- Post updated at 03:41 PM ---------- Previous update was at 03:33 PM ----------

Actually, forget about that...it is the "^" within the awk '/^Process right? If i remove it, it works...

Thanks

Great thread!
Just shows what "open" is all about:
In almost less than 6 hours, an issue submitted by an open minded user willing to find help and accepts the rules (giving the correct information asked and ready to test the propositions given then giving the results for comments...) can be solved by community effort...
A lot to learn here...