Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get a value from the contents of file

Status
Not open for further replies.

geffry

Programmer
Jun 26, 2002
33
US
I have file with lot of values.. I need to take out values from a file using shell script

file looks like
===========
start:1 (some unique number)
xyz: (some value..)
abc: (some value..)
end:1
start:2
xyz: (some value..)
abc: (some value..)
end:2
..
start:n
xyz: (some value..)
abc: (some value..)
end:n

================

I want to get value for the field "xyz" from the file along with "start" number.

how do i get the values for the field between the "start" and "end" fields. There are lot of start and end pairs in the file.

any help would be appreciated..
 
Geffry,

Something like this should get you started:

# ---- values.awk ----
/^start:/{sval = $2}
/^xyz:/{xyz = $2; print sval, xyz}

To invoke the awk script, execute the command:

awk -f values.awk input_filename

Thanks,

John
 
Hi

For section 2's xyz field :

Code:
sed -n '/^start:2/,/^end/{/xyz/p}' filename.txt

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top