Bash / 正規表現など
「独学プログラマー」を引き続き。
import random
と比べて。
# random(モジュール名)shuffle(オブジェクト名) from random import shuffle # shuffle()で直接使用できるように。 # 引数省略の場合、末尾を削除して取り出す [0, 1, 2].pop() # 2
Bash
$ echo 'Hello' $ python3 # exit()で終了 $ history $ pwd # print working directory $ cd / # 絶対パスのルートディレクトリ $ ls $ cd ~ $ mkdir abc $ .. $ rmdir abc $ touch new.txt $ ls | less $ export x = 1 $ echo $x #1 $ whoami $ sudo #super user do
正規表現 Regular Expression
$ python3 -c 'import this' $ grep -i abc AAA.txt $ grep -o abc AAA.txt #一致した単語だけ
import re line = 'This is a pen.' match = re.findall('pen', line) # リストで返す
$ grep ^When time.txt # 前方一致 $ grep dark. time.txt # .はどんな文字でも $ grep dark.$ time.txt # 後方一致
import re line = re.findall("^When", AAA, re.MULTILINE) # 複数行のとき
[abc] # 'a' or 'b' or 'c' [[:digit:]] # 数値 \d # Pythonでの数値 two* # two / twoo