reading and updating property file

I have to do a read operation for a field in property file, which looks like follows:

123|xyz|datetime|count

'|' is delimiter.

Finally I managed to read the contents of property file using statement like

cut -d"|" -f1 $PROPERTIES_FILE | tr '\n' ' '

<-- Reading first column

But now I also want some script to update. Mostly I want to update "datetime" value and "count" value which are at f3 and f4.

I found like sed command would be helpful, but dont know exactly how to do..

trying it from last few days as m beginner so it's taking time...

Thanks in Advance..!!

a="123|xyz|datetime|count"

oifs="$IFS" # save default input field delimiter

IFS="|"  # change it
val=( $a )  # parse input to the array using $IFS

IFS=$oifs   # return $IFS, if need use default ...
echo "${val[0]}"
echo "${val[1]}"

val[0]="some"
val[2]="3th"

res=${val[@]}   # all values from array
res=${res// /|} # convert all spaces => |  (values can't include spaces in this case)
echo "res:$res"

Not an efficient or direct way to do so, try a loop and the read statement. You can use the special IFS variable to control what it splits fields on. A loop would even be able to handle multiple lines.

while IFS="|" read COL1 COL2 COL3 COL4
do
        ...
done < inputfile

To update, you could do something like

while IFS="|" read COL1 COL2 COL3 COL4
do
        # Alter column 4 on every line
        COL4="newvalue"
        echo "${COL1}|${COL2}|${COL3}|${COL4}"
done < inputfile > outputfile
# Overwrite input with output
cat outputfile > inputfile
# delete outputfile
rm outputfile

---------- Post updated at 11:56 AM ---------- Previous update was at 11:51 AM ----------

Assuming the file only contains a single line, you can read and update it without the loop and without the temporary file:

IFS="|" read COL1 COL2 COL3 COL4 < inputfile
COL4="newvalue"
echo "${COL1}|${COL2}|${COL3}|${COL4}" > inputfile