innova
12-20-2004, 06:36 PM
Hi,
What is the most efficient way (in bash shell) to grab a block of text from a file? My particular problem is this:
var1=value1
var2=value2
[Section 2]
var3=value3
var4=value4
I want to be able to store the block that contains JUST the data from Section1 as a variable. Thus, I figure that I need to grab all the text between '[Section1]' and the following '[' that starts the next section.
Alternately, I could do something similar to what apache does, and close each section with . Either way, its the same basic problem.
For sake of speed, I would like to avoid using arrays if possible, as they are not too fast in bash. I know I could just do line-by-line processing into an array, and filter the unnecessary parts, but I suspect there is a much cleaner way. I would also like to not use an external language (Perl/php etc). Builtins and common external programs like sed/awk/tr are fine. Anyone have an idea?
What is the most efficient way (in bash shell) to grab a block of text from a file? My particular problem is this:
var1=value1
var2=value2
[Section 2]
var3=value3
var4=value4
I want to be able to store the block that contains JUST the data from Section1 as a variable. Thus, I figure that I need to grab all the text between '[Section1]' and the following '[' that starts the next section.
Alternately, I could do something similar to what apache does, and close each section with . Either way, its the same basic problem.
For sake of speed, I would like to avoid using arrays if possible, as they are not too fast in bash. I know I could just do line-by-line processing into an array, and filter the unnecessary parts, but I suspect there is a much cleaner way. I would also like to not use an external language (Perl/php etc). Builtins and common external programs like sed/awk/tr are fine. Anyone have an idea?
