This might look simple, But I could not get it work. I have a property file and contains like below.
AVAIL_COLS=col1,col2,col3,col4,col5
SC_AVAIL_COLS=col1,col2,col3
In my bash script, I do some processing and modifying available cols property and trying to replace it in the file. Like below.
propfile=<my property file>
line_avail_cols="AVAIL_COLS="
line_sc_avail_cols="SC_AVAIL_COLS="
available_cols=$(grep $line_avail_cols $propfile | grep -v $line_sc_avail_cols)
# Doing some operations to add few more values to same row.
available_cols="$available_cols,col6,col7,col8"
#Replace the line with new content
sed -i '/'"$line_avail_cols"'/c\'"$available_cols" $propfile
The above script works fine if my property file has only AVAIL_COLS property and not SC_AVAIL_COLS. But if the property file contains SC_AVAIL_COLS property, then instead of replacing the line, it adds as a new line in the file making duplicate entry in the file.
How to replace the AVAIL_COLS property line directly? The line number or the order of properties in file may vary. So I was looking for a generic way.
Expected OUTPUT
AVAIL_COLS=col1,col2,col3,col4,col5,col6,col7,col8
SC_AVAIL_COLS=col1,col2,col3