Hi mjl3434,
I have to say, I tend to think that bash might not be a great choice for such a task. Here's a trivial GAWK script that replaces the include file for each view. It's also rather trivial to modify it to contain a list of index of the views you would actually like to change, and then and in the further condition in the "if" statement. Alternatively, if you must use BASH, I believe a rather similar approach should work.
Code:
BEGIN {
view_include = "include \"/etc/bind/forwarder-file\";" ;
rep_view_include = "include \"/etc/bind/new-forwarder-file\";" ;
}
{
if ( $0 !~ view_include )
print $0 ;
else
print " " rep_view_include ;
}
As a simple example:
Code:
#!/bin/bash
view_include='include "/etc/bind/forwarder-file";' ;
view_indexes=( 3 7 10 ) ;
include_files=( 'include "/etc/bind/forwarder-3-file";' 'include "/etc/bind/forwarder-7-file";' 'include "/etc/bind/forwarder-10-file";' ) ;
read a_line
result=$? ;
include_count=1 ;
ra_index=0 ;
while [[ $result -eq 0 ]]
do
if [[ $a_line =~ $view_include ]]
then
if [[ $include_count -eq ${view_indexes[$ra_index]} ]]
then
echo " " ${include_files[$ra_index]}
ra_index=$(( ra_index + 1 ))
else
/bin/echo $a_line
fi
include_count=$(( include_count + 1 ))
else
/bin/echo $a_line
fi
read a_line
result=$?
done
when fed a data file created from your example data file, but extended to contain 10 views, the script outputs a new config. file with the 3rd, 7th, and 10th includes replaced. It would just need a little tweaking to reproduce the whitespace as desired.
HTH.