I have a list in the format below, how do I read through the list and extract the lines between the ##START## and ##END## , so i can check for specific values between each ##START## & ##END## pattern
---------- Post updated at 18:26 ---------- Previous update was at 18:04 ----------
shell ( bash ):
while read T
do case $T in
("##START##") continue;;
("##END##") echo $X
unset X
continue;;
(*) X+=$T" ";;
esac
done < file
RANDOMTEXT DFGSD SDFSDF
morestuff sdfggfg sdfsdf
I was having some fun with doing this in sed to produce a script to pipe to shell. The idea is that each START / END segment is numbered and the text is piped to a shell function with the segment number (first one being 1).
Might not be worth anything...
Place the following into test.sed
1i\
seg=0
/##START##/b a
b
:a
s/.*$/seg=`expr $seg + 1`/p
n
s/^/echo '/p
:b
n
/##END##/b e
p
b b
:e
s/.*$/' | call_func $seg/p
Then you can get an idea of where this could go by doing:
The contents of what?
Another random file?
A sourced set of variables?
Could you give us a much better description along with as much info as possible with real data if possible.
OS.
Shell type and version.
Real data input.
Required data output.
AND now where your contents are to check against!
LBNL where is/are your attempts at solving!
ESP is not my forte hence asking these questions...
While incomplete, my sed example outputs a shell script that could be piped into "sh". Just needs the function filled in which receives the block of text and the "segment" number. I was hoping it might put you on the right track without offering a more "complete" solution.