Filter consecutive lines
- only show the line if the line repeats more than 5 time consecutively
uniq -c text.txt | awk '$1 > 5' | sort | uniq
single quote vs double quote
-
single quotes is literal string, shell won’t identify the special shell symbols like
$and\in the string. -
e.g.
echo '$1'will not work, you have to useecho "$1" -
what about the ‘'? why - is required for both single and double quotes?
sed
use multiple -e arguments to sed the same string multiple times
Shell array
If you want to store multiple arguments in a variable, you can make them a shell array.
Example in config file, you are required to do this: ‘‘‘shell #makepkg.conf #– Command used to run pacman as root, instead of trying sudo and su PACMAN_AUTH=(sudo delayed %c) ’’’
Use parenthesis to create a shell array, which can be appended before other commands. Don’t put the quote the arguments or they will be treated as one single argument.
tee
> cannot be used if the output location requires sudo privilege. Pipe the output to tee instead.