If you want to display $variable followed by a custom string as:
$variable + '_rock'
${variable}_rock
Alternative values for a variable:
echo ${variable:-alternative value} # displays the alternative value
echo ${variable:=alternative value} # displays the alternative value and set the variable to alternative value
echo ${variable:+alternative value} # displays the alternative value only if the variable is set
Note: 'alternative value' accepts spaces.
Slicing:
variable="A very interesting string"
echo ${variable:3:1} # displays 1 chars starting from position 3 (0 is the first) = e
echo ${variable:3:5} # displays 5 chars starting from position 3 (0 is the first) = ery i
echo ${variable:3} # displays all the string starting from 3 = ery interesting string
Multiple variables access
If you define more variables which start with the same name, you can access them all at once:
fruit=banana
fruit1=orange
fruit2=lemon
echo ${!fruit*} # displays all variable names who start with fruit -> fruit fruit1 fruit2
Access their values in a loop:
for fr in ${!fruit*}; do
echo $fr = ${!fr}
done
will display:
fruit = banana
fruit1 = orange
fruit2 = lemon
tr stands for translate (or delete) characters. Here is the description: Translate, squeeze, and/or delete characters from standard input, writing to standard output.
Let's suppose that we have a test.txt with the following in it:
This is a test file. Here is the third line, with some text on it. HERE IS A CAPITALIZED TEXT. Last line is here!
$ cat test.txt | tr ' ' '.' This.is.a.test.file. Here.is.the.third.line,.with.some.text.on.it. HERE.IS.A.CAPITALIZED.TEXT. Last.line.is.here!
$ cat test.txt | tr ' ' '\ > ' This is a test file. Here is ...Note: to enter this command, after the last \ press ENTER and then continue with a quote.
$ cat test.txt | tr -d '[:punct:]' This is a test file Here is the third line with some text on it HERE IS A CAPITALIZED TEXT Last line is here
$ cat test.txt | tr '[:lower:]' '[:upper:]' THIS IS A TEST FILE. HERE IS THE THIRD LINE, WITH SOME TEXT ON IT. HERE IS A CAPITALIZED TEXT. LAST LINE IS HERE!
just switch the upper with lower and you'll get the reverse (lowercase).
$ cat test.txt | tr ' ' '\ ' | sort a A CAPITALIZED file. here! Here HERE ...
$ cat test.txt | tr ' ' '\
' | sort | uniq -ci
2
2 a
1 CAPITALIZED
1 file.
1 here!
2 Here
4 is
1 it.
...
-i, --ignore-case \\
ignore differences in case when comparing \\
-c, --count \\
prefix lines by the number of occurrences \\