SED – stream editor for filtering and transforming text
# remove all leading whitespace from line including tabs
# sed -e 's/^[ \t]*//' < inputfile
# regex example – how to find needle in a haystack
# echo "/foo/bar/filename.161212.needle-in-a-haystack.lost-forever" | /bin/sed -r 's/^.+\/filename.[0-9]{6}\.(.+?)\.lost-forever/\1/'
needle-in-a-haystack
# print out block of code starting with string and ending with empty newline
# sed -n '/string-int-the-beginning-of-block/,/^$/p' inputfile
# delete block of code starting with string and ending with empty newline, use previous example for trial runs
# sed -i '/string-int-the-beginning-of-block/,/^$/d' inputfile
# print lines starting with string from file
# sed -n '/^string-in-the-beginning-of-line:/p' inputfile
# delete lines starting with string from file, use previous example for trial runs
# sed -i '/^#string-in-the-beginning-of-line:/d' inputfile
# drop spaces from empty lines
# sed 's/^[ ]*$//'
# drop spaces from end of lines
# sed 's/[ ]*$//'
# drop spaces from empty lines, from end of lines. suppress double newlines (replace double newlines with single newline).
# sed 's/^[ ]*$//' inputfile |cat -s | sed 's/[ ]*$//'
# drop spaces from empty lines, from end of lines. suppress double newlines (replace double newlines with single newline), add empty line into end of file IF MISSING. Uses temporary files and does it for all files with yaml extension. NB! Command below is oneliner, be careful with copying.
# for f in `find . -name "*.yaml"`;do sed 's/^[ ]*$//' ${f} | sed 's/[ ]*$//' > ${f}2; echo >> ${f}2; cat -s ${f}2 > ${f}3;rm ${f}2; diff ${f} ${f}3 &>/dev/null; if [ $? -eq 1 ];then mv ${f}3 ${f}; else rm ${f}3;fi ;done
If you found this useful, say thanks, click on some banners or donate, I can always use some beer money.