Hi,
I have a file of key=value pairs,My requirement is to delete, modify in-place or append key-value pairs at will using awk(I can't use sed due to some policies). I searched in google and found following piece of code BUT I don't know how to run.when I run it's always appending one line with keytoappend=value
Could you please help regarding the below script
Thanks in advance.
# Using awk to delete, modify or append keys
# In case of an error the original configuration file is left intact
# Also leaves a timestamped backup copy (omit the cp -p if none is required)
CONFIG_FILE=file.conf
cp -p "$CONFIG_FILE" "$CONFIG_FILE.orig.`date \"+%Y%m%d_%H%M%S\"`" && awk -F'[ \t]*=[ \t]*' '$1=="keytodelete" { next } $1=="keytomodify" { print "keytomodify=newvalue" ; next } { print } END { print "keytoappend=value" }' "$CONFIG_FILE" >"$CONFIG_FILE~" && mv "$CONFIG_FILE~" "$CONFIG_FILE" || echo "an error has occurred (permissions? disk space?)"