Could anyone please help me with Assigning a value to variable and then updating the value in the original file
IFS='|'
while read -r Serial_ID JOB_NAME STATUS
do
if [ "$STATUS" = "" ]
then
echo "Perform Fuctions"
???Assign STATUS to COMPLETED and Update File???
done <File
while IFS="|" read -r SERIAL JOB STATUS
do
if [ condition ]
then
STATUS="somethingelse"
fi
printf "%s|%s|%s\n" "$SERIAL" "$JOB" "$STATUS"
done < inputfile > outputfile
Note that inputfile and outputfile can't be the same.
Files do not work that way. Even something like sed -i really just replaces or overwrites the entire file.
So I think my method should work:
cp inputfile inputfile.bak
while IFS="|" read -r SERIAL JOB STATUS
do
if [ -z "$STATUS" ]
then
do_something
STATUS="somethingelse"
fi
printf "%s|%s|%s\n" "$SERIAL" "$JOB" "$STATUS"
done < inputfile > outputfile
mv outputfile inputfile