Getting values from a block into variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting values from a block into variables
# 1  
Old 11-17-2009
Getting values from a block into variables

Hi there, If I run "ipmitool bmc info" on any of my x86 boxes, i get

Code:
Device ID                 : 32
Device Revision           : 1
Firmware Revision         : 1.1
IPMI Version              : 2.0
Manufacturer ID           : 42
Manufacturer Name         : Sun Microsystems
Product ID                : 18177 (0x4701)
Device Available          : yes
Provides Device SDRs      : no
Additional Device Support :
    Sensor Device
    SDR Repository Device
    SEL Device
    FRU Inventory Device
    IPMB Event Receiver
    IPMB Event Generator
    Chassis Device
Aux Firmware Rev Info     : 
    0x08
    0x00
    0x00
    0x00

Im trying to figure out a way of getting the four values directly underneath the string "Aux Firmware Rev Info :" into their own variables as i need to evaluate each of them to get the overall firmware revision


Does anybody have any idea how i would get these 4 values (and there are always 4) into variables? would i have to put them in some sort of array.

any help or guidance on this would be greatly appreciated

PS: I can technically do this by doing a "tail -4 | head -1" operation, then a "tail -3 | head -1" etc etc ....but im assuming there is a more stable and effective way of doing this
# 2  
Old 11-17-2009
Ttry this :
Code:
grep -A4 "Aux Firmware Rev Info" input.txt

Or more direct
Code:
ipmitool bmc info | grep -A4 "Aux Firmware Rev Info"


Last edited by frans; 11-17-2009 at 08:37 AM.. Reason: added more code
# 3  
Old 11-17-2009
thank you frans, but unfortunately im running Solaris and don't have a -A argument available to me .
# 4  
Old 11-17-2009
One way:

Code:
ipmitool bmc info | awk -v ORS=" " '/Aux Firmware Rev Info/{getline;p=1}p' | read var1 var2 var3 var4

# 5  
Old 11-17-2009
thanks for that, it seems that the $var's have been populated with only blank characters (see below) ..

Code:
#ipmitool bmc info | awk -v ORS=" " '/Aux Firmware Rev Info/{getline;p=1}p' | read var1 var2 var3 var4
#echo $var1

#

if i drop the read, i get


Code:
#ipmitool bmc info | awk -v ORS=" " '/Aux Firmware Rev Info/{getline;p=1}p'                           
    0x08     0x00     0x00     0x00 #

I guess somehow i need to get rid of the whitespace before reading
# 6  
Old 11-17-2009
You also have a "#" in your file, what are the contents of the other variables?
# 7  
Old 11-17-2009
the hash is the prompt for the next command as it seems a carriage return is not sent after awk statement

All four variables contain whitespace, is it reading every other space, and as such using up the variables before it even gets to the first real piece of data ? (due to the fact there are quite a few spaces before the first bit of data)


edit: i have just run

Code:
ipmitool bmc info | awk -v ORS=" " '/Aux Firmware Rev Info/{getline;p=1}p'| read var1 var2 var3 var4 var5 var6 var7 var8 var9

and all are empty

Last edited by rethink; 11-17-2009 at 09:51 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract multiple values into corresponding variables

Here is my input # MANIFEST.MF Manifest-Version: 1.0 Build-Jdk: 1.6.0 Built-By: CM_TEAM Build_SvnRev: 662789 Build_Number: 13.0.0.0-JDK8 Build_Date: Wed 04/05/2017-20:48:19.17 Archiver-Version: Plexus Archiver Created-By: Apache Maven 3.1.0 Here is the expected output:... (4 Replies)
Discussion started by: kchinnam
4 Replies

2. Shell Programming and Scripting

A better way to assign values to variables - shell

so i've been used to doing it this way: SVAL=$(echo "7 3 2 38 3" | awk '{print $2}') 4VAL=$(echo "4:21:N:3" | awk -F":" '{print $4}') I know there's a way to do it by putting the value in an array and assigning it that way. but i'm not sure how to do it efficiently. any ideas? i dont... (9 Replies)
Discussion started by: SkySmart
9 Replies

3. Shell Programming and Scripting

Get values block by block in same file

I have a file say "SAMPLE.txt" with following content, P1 10,9:6/123456 P2 blah blah P1 10,9:5/98765 P2 blah blah P1 blah blah P2 I want a output file say "RESULT.txt" as, Value1:123456 Value2:98765 Value3:NULL (17 Replies)
Discussion started by: garvit184
17 Replies

4. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

5. Shell Programming and Scripting

Exporting Values of Variables to Another File

Hello, I'm very new to Linux, and I have a question, I'm hoping you could help me with. :) I have created a file called subject, contains this code: #!/bin/bash read -p "Student Name: " NAME read -p "Student ID: " ID read -p "Address: " ADDRESS I'm to create another file called... (7 Replies)
Discussion started by: iwant2learn
7 Replies

6. Shell Programming and Scripting

Help in assigning values to variables from the file

Hi! This might be a simple thing, but I'm struggling to assign values to variables from the file. I've the following values stored in the file.. It consists of only two rows.. 10 20 I want to assign the first row value to variable "n1" and the second row value to variable "n2".. That is ... (3 Replies)
Discussion started by: abk07
3 Replies

7. Shell Programming and Scripting

How to use values in variables

Hi Legends, Please help me in solving the below: I have the file size and file name using `ls` and awk command. ls -ltr *.pf |awk '{print $5, $9}' 2000003072 ABC.pf 2000003072 DEF.pf 2000003072 GHI.pf 56000588 JKL.pf 2000003072 MNO.pf 2000003072 PQR.pf Now, I want to take the... (3 Replies)
Discussion started by: sdosanjh
3 Replies

8. Shell Programming and Scripting

Assign values to variables of a file

Hi, I have a file like the following... CUST= DIR= NULIST= name=philps_123 How can i add values to each of these unassigned variables using a shell script? say for eg: i have values for CUST as onida, dir as /dir/onida, NULIST as /tmp/onida_files. How can i add these values to... (11 Replies)
Discussion started by: Tuxidow
11 Replies

9. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

10. Shell Programming and Scripting

Parsing and getting values of variables

suppose i have a file value where it returns 3 values a=1 b=2 c=4 when i run it. i am using this file in my shell script. how do i parse and get the value of a b and c? (3 Replies)
Discussion started by: Rekha
3 Replies
Login or Register to Ask a Question