ich habe eine Datei wie folgt:
Code: Alles auswählen
foo=bar
#START
bar=foo
#END
bla=blub
//Edit: Lösung:
Code: Alles auswählen
#!/bin/sh
# reads options (var = val) line-wise from STDIN and writes them to $1
# by replacing the START-END region
set -e
if [ ! -e "$1" ]; then
printf "%s\n%s\n" "#START" "#END" >"$1"
fi
# has the file markers and the right way round?
awk '
/^#START$/ {ls=NR; s++}
/^#END$/ {le=NR; e++}
END {
if (s!=1||e!=1||le < ls) {
printf("%s: missing, half-open or more than one START-END region.\n", "'$1'");
exit 112;
}
}' "$1" >&2
# replace START-END region
sed -i '/^#START$/,/^#END$/c \
#START\
# Do not edit within this region\! Make youre changes after the END mark.\
'"$(while read option; do echo "$option\\"; done)"'
#END' "$1"