I am working on a configuration file parser, written in a bash script. I am parsing a file where each line is in the form of
[comment][option title][comment]: [option value]
where [comment] is either " *[anything]* " or "". The problem is that egrep will find the lines I need, but sed will not remove the option tag for me.
Here is a simplified version of my script (sorry, no Linux here so I can't test it...):
Code:
#!/bin/bash
beg="^"
end=":"
mandspc="[ ]*"
cmt="($mandspc\*.*\*$mandspc|)"
error="config_error"
function extract()
{
tag="$beg$cmt$1$cmt$end$mandspc"
if [ `egrep -c "$tag" "$file"` -ne 1 ]; then
echo "$error"
else
egrep -h "$tag" "$file" | sed "s/$tag//"
fi
}
echo "`extract \"extport_fs\"`"
(In case you can't tell, that is a space and a tab in mandspc.)
Here is the part of my config file applicable (file named ext-config):
Code:
* file system for extport * extport_fs: ext2
egrep can find the line just fine, however sed will not remove the "file system for extport * extport_fs: " from the line. Can you see anything I'm doing wrong as far as the regex? Is there something besides sed that I can use? It's still in "working" status, therefore I am going to change the style of the lines once I get it working. Thanks.
ta0kira
[EDIT] Made it a little more easy to read...