Regex
- . : any one character
- * : match any number of previous (include 0)
- + : match any number of previous
- $ : end of the line
- ^ : beginning of the line
- [^] : any character but the ones in brackets
- \S : any none white space character
- \s : any white space character
- \b : any border (any white space/end of file not included in the returned match)
- ? : optional
- [a-z] : any lowercase letter
- [A-Z] : any uppercase letter
- [a-zA-Z] : any letter
- [0-9] : any number
- \ : scape something
Tips
General
Grep
Sed
Cut
Awk
\t # tab in strings in print and printf
\n # new line in strings in print and printf
%ns # A n characters string in printf
%nd # A n characters integer in printf
%n.mf # A n.m characters float in printf
a += b # a = a + b
Flags
-f # Get path of an awk script file
-F”,” # Set a delimiter
== vs ~ : exact match vs contain the pattern
! : not
$0 : whole line
$1 $2 … : first column second column ..
Special Variables
NR : number of record (line number)
NF : number of field (column number)
FNR : file number of record (line number of input file)
FS : field separator
FPAT : field pattern
FILENAME: file name of input file
ARGC : how many input arguments are passed to the awk code
ARGV : an array of arguments that are passed to the awk code
tolower : lower case all characters
Array
array[key] = value
Dimensional Arrays
array[key1][key2] = value
Example 01
ex1.awk:
input.txt
Functions
Heredoc
Autorotation With Xrandr
Fun
List all packages that explicitly installed on arch
Small script to generate a random password. Works on Linux with busybox, haven’t tested on GNU.
Net usage:
Paste a command output to a pastebin:
If you are stuck in a terminal and don’t want to use hastebin.com
, you can use ix.io or paste.rs to paste from the CLI:
GNU parallel
Executing jobs in parallel
TTY screenshot