Skip to content

Instantly share code, notes, and snippets.

@u1and0
Last active January 15, 2019 06:45
Show Gist options
  • Select an option

  • Save u1and0/3d64ca78e0d2812baefd12e2b1b9fc72 to your computer and use it in GitHub Desktop.

Select an option

Save u1and0/3d64ca78e0d2812baefd12e2b1b9fc72 to your computer and use it in GitHub Desktop.
oneliner command line
# Shell commends
```sh
expac -HM '%m %n' | sort -n # display installed packages size
```
# Vim scripts
```vim
:w !tweet.sh " 選択範囲をツイート投稿.depends https://github.com/ShellShoccar-jpn/kotoriotoko
:w `=tempname()` | vim package % | cw " 現在のバッファの無名バッファを適当な名前で保存しながらpackageという文字列で検索してquickfix listに表示する
:b# | r!column -s, -t "#" " 現在開いているcsvファイルのカラムを空白埋めに変えて空のバッファに読み込む.`column`コマンドが必要
:au BufWritePost *.go !go fmt % " go言語ファイルの書き込みを行うとき、自動的にgo fmtを走らせる
```
```awk
# 1から10までのランダムな数字を5つ
for i in `seq 5`; do echo $(($RANDOM%10)); done
#合計
for i in `seq 5`; do echo $(($RANDOM%10)); done |
awk '{a+=$1}END{print a}'
# 平均値
seq 10 | awk '{a+=$1}END{print a/NR}'
# 行数NR, 標準入力から受け取ったランダム数、cumsum
for i in `seq 5`; do echo $(($RANDOM%10)); done |
awk '{a+=$1;print NR,$1,a}'
for i in `seq 5`; do echo $(($RANDOM%10)); done |
perl -nE '$sum+=$_;print $_;END{print $sum}'
# awk式tac(連想配列を使う)
seq 10 | awk '{line[NR] = $0}END{for(i=1;i<=NR;i++){a+=line[i];print line[i]}}'
# 全行を配列に格納して、合計を算出し、配列の内容を吐き出しながら合計で割る
seq 10 | awk '{l[NR]=$1;s+=$1}END{for(i=1;i<=NR;i++){print l[i],l[i]/s}}'
# 算術計算
awk 'BEGIN {print sin(1) / cos(1)}'
1.55741
# pi
awk 'BEGIN {print atan2(0, -0)}'
3.14159
awk 'BEGIN {print 90 * atan2(0, -0) / 180}'
1.5708
awk 'BEGIN {print log(100) / log(10)}'
2
awk 'BEGIN{print exp(1)}'
2.71828
# ランダムだけど何度も同じ数字を出す。
# 返す数字はAWKをビルドした環境に依存
awk 'BEGIN {print rand()}'
0.237788
# 10個のランダム数を返す
awk 'BEGIN {for(i=0;i<10;i++){print i,rand()}}'
0 0.924046
1 0.593909
2 0.306394
3 0.578941
4 0.740133
5 0.786926
6 0.43637
7 0.332195
8 0.77888
9 0.1
# 1-10のランダム数
awk 'BEGIN {print int(rand() * 10) + 1}'
3
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment