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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a "word" through grep but display line above?
# 1  
Old 09-22-2010
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.

Last edited by vbe; 09-22-2010 at 10:50 AM.. Reason: rearranging...
# 2  
Old 09-22-2010
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.
Code:
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 $

# 3  
Old 09-22-2010
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.
# 4  
Old 09-22-2010
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 ?
# 5  
Old 09-22-2010
The output of a "query process" within TSM is this:
Code:
     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...


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by Franklin52; 09-22-2010 at 02:08 PM..
# 6  
Old 09-22-2010
Try:
Code:
sed -n '/^Process Number/{N;N;N;s/^Process Number:[ \t]*\([0-9,]*\).*Waiting for mount.*/\1/p}' infile

output:
Code:
32,901
32,902

# 7  
Old 09-22-2010
Quote:
Originally Posted by Scrutinizer
Try:
Code:
sed -n '/^Process Number/{N;N;N;s/^Process Number:[ \t]*\([0-9,]*\).*Waiting for mount.*/\1/p}' infile

output:
Code:
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...Smilie Just started using grep and awk...now sed?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Add the word "prefix" to beginning of line using sed

SUSE linux bash shell this works test -d /tmpp && echo "directory exists" || echo "directory doesn't exists" |sed -e "s/^/prefix /" prefix directory doesn't exists but why doesn't this work? test -d /tmp && echo "directory exists" || echo "directory doesn't exists" |sed -e... (3 Replies)
Discussion started by: snoman1
3 Replies

3. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

4. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

7. UNIX for Dummies Questions & Answers

Display all the lines that contain "Straw" followed somewhere in the line by Hat?

how do i use this in a grep pattern, the output is inventory (3 Replies)
Discussion started by: 3dd1e
3 Replies

8. Shell Programming and Scripting

cat/delete per line any word "192.168.1.12"

Hi All Can u help me.. My problem is delete word per line sample: cat /tmp/file.txt monitor 192.168.1.11 Copying files in current directory 1 monitor 192.168.1.1 Copying files in current directory 2 monitor 192.168.1.12 Copying files in current directory 3 monitor 192.168.1.14... (1 Reply)
Discussion started by: carnegiex
1 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

10. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies
Login or Register to Ask a Question