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?
# 8  
Old 09-22-2010
use Perl to get the paragraph which contains the word "Waiting" ...

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

Smilie
# 9  
Old 09-22-2010
I would do that, yes, if q proc produces output like you described above...
# 10  
Old 09-22-2010
Code:
awk '/^Process /{x=(x)?x FS$0:$0}/Waiting/{print x}!NF{x=z}' infile

# 11  
Old 09-22-2010
Try:
Code:
awk '/Waiting/{print $3}' RS= file

# 12  
Old 09-22-2010
Hehehe Franklin52, of course Smilie
# 13  
Old 09-22-2010
Quote:
Originally Posted by Scrutinizer
Hehehe Franklin52, of course Smilie
Look nice but what about the OP requirement?
Quote:
Originally Posted by Stephan
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?
# 14  
Old 09-22-2010
Quote:
Originally Posted by danmero
Code:
awk '/^Process /{x=(x)?x FS$0:$0}/Waiting/{print x}!NF{x=z}' infile

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
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