grep the output between specific lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep the output between specific lines
# 1  
Old 10-04-2012
grep the output between specific lines

Symmetrix ID : 00000001234

Host Name : myown

Identifiers Found : 5000000000000000
5000000000000001

Device Cap(MB) Attr Dir:P
------ ------- ---- ----
1234 25886 (M) 8D:1, 9D:1
0123 25886 (M) 8D:1, 9D:1
1345 25886 (M) 8D:1, 9D:1
1576 17261 (M) 8D:1, 9D:1
1456 17261 (M) 4B:0,13B:0

-----------------------------

MB Total: 363879
GB Total: 355.4
[/CODE]My output should be

Code:
myown : 355.4 GB
 
1234    25886
0123    25886
1345    25886
1567    17261
1456    17261

below is awk to get this output myown 355.4

myown : 355.4 GB : 1234,0123,1345,1567,1456

Code:
egrep "Host Name|GB Total"|awk '{print $NF}'|sed 'N;s/\n/ /;s/$/ GB/'

please help modifying to get dev and cap as well for each server

Last edited by maddy.san; 10-08-2012 at 08:15 AM.. Reason: code tags
# 2  
Old 10-04-2012
You may want to write an awk script...

put the following into a file "filter.awk"
Code:
{
    if ($0 ~ /^-/) { dash++ } else { if (dash==1) {out[++outcnt] = sprintf("%s %s",$1, $2) } }
    if (match($0, "Host Name : |GB Total: ")) { hdr[++hdrcnt] = substr($0, RLENGTH + 1)}
}
END { printf("%s : %s GB\n\n", hdr[1], hdr[2]);  for (i=1; i<=outcnt; i++) { print out[i] } }

awk then do
Code:
awk -f filter.awk YOURFILE

This User Gave Thanks to scottaazz For This Post:
# 3  
Old 10-04-2012
Another awk:
Code:
awk '/^[0-9]/{sub(/ *\(.*/,x); v=v RS $0} /Host Name/{n=$4} /GB Total/{print n " : " $3,$1 RS v}' infile

# 4  
Old 10-04-2012
Thanks it worked! can you please explain how the above awk works
# 5  
Old 10-08-2012
Please help me in formatting output as below :

myown : 355.4 GB : 1234,0123,1345,1567,1456
# 6  
Old 10-08-2012
Code:
awk '/^Host Name/{sub(/.*: /,"");m=$0;next}
/^[0-9]/ && NF>2{line=(length(line))?line","$1:$1;next}
/^GB Total/{print m " : " $3,$1 " : " line }' file

This User Gave Thanks to elixir_sinari For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep content between specific lines

cat file1 *FileHeader* Partition 0 Total Data Bytes 1416 Avg Bytes/Record 1416 Others 1 PRDX22.AUDIT_DATA_INFO Partition 4 Total Data Bytes 4615 Avg... (8 Replies)
Discussion started by: Veera_V
8 Replies

2. UNIX for Dummies Questions & Answers

Grep specific lines

Hello I have a file with nearly 90000 lines in x,y,z format but have some lines that I do not need to show. Is there anyway to delete those 3 lines after every 288 lines. Eg I keep the first 288 lines delete (289, 290 291); keep the next 288 lines after those and so on... Thanks (6 Replies)
Discussion started by: Madiouma Ndiaye
6 Replies

3. Shell Programming and Scripting

How to grep logs for errors and receive specific additional lines?

Hi there, I have a script that I've used to find errors in my Minecraft Server logs. But I'd like to refine that script to be more useful. Here is the script: grep -n "SEVERE" /minecraft/server.log | awk -F":" '{print $1-2 "," $1+10 "p"}' | xargs -t -i sed -n {} /minecraft/server.log >>... (15 Replies)
Discussion started by: nbsparks
15 Replies

4. Shell Programming and Scripting

Grep all lines for a specific date in log-files

I need to grep all lines for "yesterday" in /var/log/messages. Dates are in the format "YYYY-MM-DD". (5 Replies)
Discussion started by: Padmanabhan
5 Replies

5. Shell Programming and Scripting

Grep only specific lines ordered by column/date

Hi everybody, I'd like to think I've been through the search tool not only on this site, but also on google too, but I haven't been able to find what I was looking for. If I might've missed something on this forum, please slap me in the face with a link that you consider useful for my query :D ... (4 Replies)
Discussion started by: dilibau
4 Replies

6. Shell Programming and Scripting

Problems to print specific lines with awk and grep...HELP!

Hi all I have data like this: model: 1, misfit value: 0.74987 1 1.182 1.735 2.056 1.867 2 0.503 1.843 2.018 1.888 3 2.706 2.952 2.979 1.882 4 8.015 3.414 3.675 1.874 ... (1 Reply)
Discussion started by: fedora2011
1 Replies

7. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

8. Shell Programming and Scripting

Remove a specific line from grep output string

Dear All I want to search string "1000" from input file and if it found i want remove line that contain 1000 and also remove 3 line above it and 2 line below it. INPUT FILE: BHAT-D 2 aaa ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES 50 ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

9. UNIX Desktop Questions & Answers

grep lines with two specific characters somewhere in the line

I'm having trouble with extracting certain lines from a file based on whether they have all the required fields. Original file: snt:594:Sam N This bpt:2342:Bob P That lr:123 wrp:23:Whoever Person cor:794 Desired output: snt:594:Sam N This bpt:2342:Bob P That wrp:23:Whoever Person ... (3 Replies)
Discussion started by: Chthonic
3 Replies

10. Shell Programming and Scripting

retrieving specific lines from a file - can I use grep ?

Hi there, if i had a file that looked like this my_server1 red green blue yellow blue my_server2 blue blue yellow green blue my_server3 yellow (9 Replies)
Discussion started by: hcclnoodles
9 Replies
Login or Register to Ask a Question