Extract multiple lines of data from a text file.
I need to take out like I have listed below and extract all the ALU Numbers out so I use those in another command. The length of the file changes so the line number is not exact. If I can at least extract out the lines with the ALU numbers then it is easy enough to remove the column I don't need. Any suggestions on what I can use to grab just those lines.
Here is an example of the type of output I am working with. Storage Group Name: miux11_sg Storage Group UID: C2:F3:D6:E8:F0:4A:DE:11:8A:FC:00:60:16:25:9F:FA HBA/SP Pairs: HBA UID SP Name SPPort ------- ------- ------ 20:00:00:00:C9:43:46:3B:10:00:00:00:C9:43:46:3B SP B 6 20:00:00:00:C9:43:46:5F:10:00:00:00:C9:43:46:5F SP A 6 20:00:00:00:C9:43:46:5F:10:00:00:00:C9:43:46:5F SP B 7 20:00:00:00:C9:43:46:3B:10:00:00:00:C9:43:46:3B SP A 7 HLU/ALU Pairs: HLU Number ALU Number ---------- ---------- 0 24 2 303 3 311 4 327 5 304 6 312 7 25 8 20 10 297 11 305 12 313 13 102 14 287 1 23 9 22 17 328 18 222 15 191 Shareable: YES Thanks for the help, Shawn |
grep?
|
You gave us what you started with but not what you would like to end up with??
I would say awk, but hard to tell without know what you want. What have you tried??? |
First, we need to define what is the unique attribute of the lines to be extracted. Looking at your sample, it could be:
1. Everything between "HLU Number ALU Number" and "Shareable" 2. Every line containing exactly 2 numbers and nothing else. The second one is maybe the easiest (NOT TESTED): Code:
sed -n -r '/^[0-9]+ [0-9]+$/p' filename Code:
sed -n -r '/^[0-9]+ [0-9]+$/s/^[0-9]+ //p' filename http://www.grymoire.com/Unix/ look at both SED and AWK |
Data that needs to be extracted.
In the output that I start with after the lines:
HLU Number ALU Number ---------- ---------- There are sets of numbers and I need to extract just those numbers. Ideally I only want the numbers under the ALU Number column. I only want to extract numbers and just up to the line that starts with "Shareable:" If I extract the numbers under HLU Number as well I know how to run that output through awk to just get ALU Numbers. So in the above example I want the output of: 24 303 311 327 304 312 25 20 297 305 313 102 287 23 22 328 222 191 Once I get that data I plan on putting them in a loop. |
Did you try my solution?
|
Pixellany,
I tried the commands and did not get any output. The idea is what I am looking for because it is only lines with two numbers in it that I need to extract. |
pixellany,
Thanks for pointing me in the write direction. The syntax I ended up using is this: sed -n -r '/^[ ]+[0-9]+[ ]+[0-9]+$/ p' |
I have just given you your first "thank you".
Why? You posted a rational question You posted follow-up You took my knee-jerk suggestion, understood it, and then fixed it. You posted your results. You have no idea how rare this is----looking forward to seeing you here more. |
All times are GMT -5. The time now is 02:26 PM. |