LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2014, 12:15 PM   #1
mightyh
LQ Newbie
 
Registered: May 2014
Posts: 3

Rep: Reputation: Disabled
print value from offset row with bash


I have a command that provides system config info for each volume. I am trying to query a file containing the information for each volume, search out a volume group and respond with the associated volume. So basically

if the associated volume group = x then print volume name.

Code:
Volume name:                   2

Volume status:                 Optimal
Thin provisioned:              

Capacity:                      ##### GB
Volume world-wide identifier:  
Subsystem ID (SSID):          
Associated volume group:       4
RAID level:                    

LUN:                           
Accessible By:                 

Drive media type:              
Drive interface type:          
Tray loss protection:          

Secure:                        

Data Assurance (DA) enabled:   

Preferred owner:               
Current owner:                 



Volume name:                   5

Volume status:                 Optimal
Thin provisioned:              

Capacity:                      ##### GB
Volume world-wide identifier:  
Subsystem ID (SSID):          
Associated volume group:       5
RAID level:                    

LUN:                           
Accessible By:                 

Drive media type:              
Drive interface type:          
Tray loss protection:          

Secure:                        

Data Assurance (DA) enabled:   

Preferred owner:               
Current owner:

Last edited by mightyh; 05-06-2014 at 03:03 PM.
 
Old 05-06-2014, 01:51 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,000

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Sounds like a great idea ... so what have you done to solve the problem? Also, is the data shown the answer or what we are to start with?

Please also place code / data in [code][/code] tags to make it more readable.
 
Old 05-06-2014, 03:14 PM   #3
mightyh
LQ Newbie
 
Registered: May 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
That is a sample of the data that i am trying to parse. I will turn the solution into a variable "$volumename" for another function.

I have a basic understanding of awk so i can definitely find the line with associated volume group but i am at a loss on how to print the volume name from 8 rows up.

This will find the line with volumegroup 1 and print it. But what i need is to print the volume name.
Code:
volumegroup = 1
awk -v volumegroup=$volumegroup -F":" '$1 ~ /volume group/ && $2 ~ volumegroup {print}'
 
Old 05-07-2014, 07:29 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,000

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
So why not store the volume name as you come across them and then when your expressions are correct you can print the saved value
 
Old 05-08-2014, 05:36 PM   #5
mightyh
LQ Newbie
 
Registered: May 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
I would be grateful if you would show me how to do that, or point me to an existing thread.
 
Old 05-09-2014, 02:51 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,000

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Same idea as what you have already done, simply add something like the following to the start:
Code:
$1 = "Volume name"{vname = $2}
To get just the name, seeing as there is a good deal of white space everywhere, I would add this to your separator so it is absorbed:
Code:
-F": *"
If there are tabs in there as well you will need to alter to suit
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Print on terminal specifying columns and row? Drigo Linux - Newbie 8 04-14-2013 06:43 AM
SSH Error taipei kernel: EDAC MC0: UE page 0x0, offset 0x0, grain 1073741824, row 7, ramesh_india2020 Linux - Newbie 1 09-23-2010 12:43 AM
sorting a file at a certain offset in bash matt007 Linux - Software 4 06-24-2008 04:03 PM
Print-out is offset Cichlid Linux - Hardware 1 05-06-2002 04:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration