Tag Archives: BASH

[TIP] Force variable substitution within single quotes in BASH

Sometimes in a BASH script you need to have single quotes but the value inside them is actually a variable. Here is how to have both the single quotes and the actual value of the variable expanded. % foo=bar % … Continue reading

Posted in console | Tagged | 4 Comments

[TIP] Count non-empty lines in a text file

grep -c -v ‘^$’ filename If you want to, as well, exclude lines which contain only spaces: grep -c -v ‘^ *$’ filename Notes (from the grep man page): -c, –count Suppress normal output; instead print a count of matching … Continue reading

Posted in console | Tagged , , | Leave a comment