Shell oneliners

Created: by Pradeep Gowda Updated: Apr 23, 2023 Tagged: code

xargs+grep+cut+sed for text replacement

To replace all occurrences of comments: 1 with comments: True in all the “html” files under the directory.

$ find . -type f -name "*.html" | xargs grep -i ^comments: | cut -d: -f 1 | xargs sed -i -e "s/comments: 1/comments: True/"

Print the UTC time and the name of the latest html file to be changed in the templates directory.

find templates -type f -name "*.html" |\
TZ="UTC" xargs ls -l --time-style=+%Y%m%d%H%M%S |\
awk '{print $6 " " $7}' | sort | tail -n 1