Day: December 7, 2020

Bash: printf

Also see: https://linuxize.com/post/bash-printf-command/ Format Placeholder Syntax Flags Some commonly used: – Left align the printed text within the field. (default: right-aligned) + Prefix the numbers with a + or – signs. (default: no + for positive number).Negative number is always is prefixed with -. 0 Pads numbers with leading zeros rather than space. Also see: https://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.html#Integer-Conversions Specifiers Some commonly …

Bash: printf Read More »

Bash: Split One String Into Multiple Variables

Split “abc-123” into two variables by – Using awk Using cut Using IFS and read Using Shell Parameter Expansion/Substitution See: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html https://tldp.org/LDP/abs/html/parameter-substitution.html ${var%Pattern} Remove from $var the shortest part of Pattern that matches the back end (right) of $var. ${var%%Pattern} Remove from $var the longest part of Pattern that matches the back end (right) of $var. ${var#Pattern} Remove from $var the shortest part of $Pattern that matches the front end (left) of $var. ${var##Pattern} Remove from $var the longest part of $Pattern that matches the front end (left) of $var.