Bash
Bash
BASH
#!/bin/bash -e
echo $@
first_arg=shift
Some commands:
- nproc: returns number of processing units available to the process
awk
General pattern:
awk -F "." "/regex1/{ print $2 } /regex2/{ print $2 }" file1 file2 ... fileN
Special control variables:
- FS: field separator (default: whitespace)
- RS: record separator (default: new line \n)
- OFS: output field separator
- ORS: output record separator
Special information variables:
- NF: number of fields in the current record
- NR: number of record since the beginning
- FILENAME: current file being processed
- FNR: number of record of the current file
Field variables:
- $0: whole line
- $(x): Field number x. Can be $($(1)). Writing to field variables forces a regeneration of $0. Can write to non-existent fields.
Operators, mostly C operators and in addition:
- ~ regular expression match
Assign values in BEGIN action. Multiple actions can be combined:
awk 'BEGIN{FS='.'; RS="!"} /up/{print $1} /down/{ print $1 }' input_file.txt
sed
Replace all occurences of something into nothing:
for I in *.txt; do sed -i "s/something/nothing/" $I; done
Tcl/Tk
From here, find the right event to bind to:
package require Tk
pack [text .t -bg white]
bind .t <KeyPress> {puts "You pressed the key named: %K "}
bind .t <ButtonPress> {puts "You pressed button: %b at %x %y"}
Emacs
Navigation
Ctrl+n next character
Ctrl+p previous character
Meta+n next word
Meta+p previous word
Dotty
Git
Nice tutorials:
Multipurpose commands:
- git checkout:
- get a particular commit
- change to a branch
- git branch:
- get list of branches
- create a new branch
Main commands:
# Repo creation
git clone /repo/path .
git init .
# Adding changes
git add file
git commit -m "Commit message" # Add list of files for targeted commit
# Status
git status
git log
git log --graph --decorate --abbrev-commit --all --date=local --pretty=format:\"%C(auto)%h%d %C(blue)%an %C(green)%cd %C(red)%GG %C(reset)%s\" --date=local
Fixing the last commit:
git add forgot_this_file.txt
git commit --amend
# Add --no-edit above to skip message prompt
Syntax for versions:
- ~ : parent of version
- ^ : Selects among multiple parents (as in a merge)