Just Random Stuff
Regex for IP (Starting with zero is included)
^((?![3-9][0-9]{2}|2[6-9][0-9]|25[6-9])[0-9]{1,3}\.){3}(?![3-9][0-9]{2}|2[6-9][0-9]|25[6-9])[0-9]{1,3}$
Password generator in a SHELL
echo -e {1..20}"\r$(tr -dc a-z0-9A-Z < /dev/random | head -c 20)\n"
Print additional 3 lines after pattern matchs
cat somefile.txt | sed -n '/pattern/ {N;N;N;p}'
Print N-th colored output after patter match
cat somefile.txt | sed -e '/pattern/ { s/^/\x1b[32m/; N;N;N; s/$/\x1b[0m/}'
Match text from pattern1 to patter2
cat somefile.txt | sed -n '/pattern1/,/pattern2/p'
Cut out text in between pattern1 and patter2
cat somefile.txt | sed -e 's/.*pattern1\(.*\)pattern2.*/\1/'
Color the text from pattern1 to pattern2
cat somefile.txt | sed -e '/pattern1/,/pattern2/ { s/^/\x1b[32m/; s/$/\x1b[0m/}'
To match brackets use HEX \x27="'"
For loop replacement in line here "t" is the operator for loop
echo ",,;;,,,,;;;," | sed ':loop; s/,,/,/; t loop'
To pass the variable in 'sed', double quotes are required around SED script OR put the variable inside the single quotes
cat somefile.txt | sed -e "s/pattern/$ANY_VARIABLE/g"
cat somefile.txt | sed -e 's/pattern/'$ANY_VARIABLE'/g'
-
'name' will be the variable.
name="my.own.domain.org"
(in this case "." is only delimiter "." can be any character) -
echo ${name%.*}
- result : my.own.domain
-
echo ${name%%.*}
- result : my
-
echo ${name#*.}
- result : own.domain.org
-
echo ${name##*.}
- result : org
-
echo ${#name}
- result : number length of the string
-
echo ${name^^}
- result : All Upper case
-
echo ${name,,}
- result : All Lower case
-
echo ${name::3}
- result : Displays first 3 characters
-
echo ${name:3}
- result : Displays all except first 3 characters
-
echo ${name:3:5}
- result : Skips 3 first characters and displays following 5
-
echo ${name/st1/st2}
- result : Replace first match 'st1' with 'st2' in 'name'
-
echo ${name//st1/st2}
- result : Replace all match 'st1' with 'st2' in 'name'
Get GNOME's current theme name
gsettings get org.gnome.desktop.interface gtk-theme