Add automatically to-do items to README.md #Ubuntu #Shell #Algorithm
#!/bin/bash
# If you want to check for duplicates and add only the lines that don't exist
# Remove all whitespaces from the start of file
sed "s/^[ \t]*//" -i ~/.todo
# Add all the completed todo items to the README.md list
input="/home/unkown/.todo"
while IFS= read -r var
do
# echo "- [x] $var" >> /home/unkown/scripts/setup_scripts-test_studio/README.md
# remove any whitespaces if exist
OUTPUT="$({ echo "- [x]"; echo -n $var;} | tr "\n" " ")"
LINE="$OUTPUT"
# add this to the file
FILE=/home/unkown/scripts/setup_scripts-test_studio/README.md
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
sed -i 's/[[:space:]]*$//' $FILE
done < "$input"
# If you don't want to check for duplicate lines
# Add all the completed todo items to the README.md list
input="/home/unkown/.todo"
while IFS= read -r var
do
echo "- [x] $var" >> /home/unkown/scripts/setup_scripts-test_studio/README.md
# remove any whitespaces if exist
LINE="$var"
# add this to the file
FILE=/home/unkown/scripts/setup_scripts-test_studio/README.md
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
sed -i 's/[[:space:]]*$//' $FILE
done < "$input"