LoginSignup
3
0

More than 1 year has passed since last update.

使えるかもしれない AWK & sed & コマンド 集 19 (MAC用)

Last updated at Posted at 2021-12-10

こんにちはエンジニアのG高橋です。
良いネタが思いつかなかったので、
手元にある過去によく使っていたコマンドをまとめてみました。

特に役立つ知識ではないのでお暇な方のみご覧ください。

1. サブディレクトリのグラフィカルツリー

$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

2. ソートせずにファイル内の重複エントリを削除します。

$ awk '!x[$0]++' sample_file.txt

3. ファイル内の長い行を特定する

$ awk 'length>290' sample_file.txt

4. マシンのIPアドレスを素早く確認

$ curl -s icanhazip.com

5. 簡易ストップウォッチ

$ time read (※ ctl+dでストップ)
^D
real    0m3.625s
user    0m0.000s
sys 0m0.000s

6. less を途中からtailに変える

$ less sample_file.txt
 (※表示中に大文字Fを押す)

7. マトリックス風

$ LC_CTYPE=C tr -c "[:digit:]" " " < /dev/urandom  | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"

matrix.gif

8. 特定の列をターゲットにしてパターン置換を行う

$ awk '{gsub("hoge","fuga",$5)}1' sample_file.txt

➔ 5列目のみ、hogeのすべてのインスタンスをfugaに置き換えます。

9. サイトのSSL証明書の日付を確認する

$ echo | openssl s_client -connect www.google.com:443 2>/dev/null |openssl x509 -dates -noout

10. BASHのコマンド出力から複数の変数を割り当てる

$ read day month year <<< $(date +'%d %m %y')
$ echo $day
 09

11. クイック計算機能

$ ? () { echo "$*" | bc -l; }
$ ? 20*1+3
23

12. ファイルの名前をすばやく変更

$ touch test.txt
$ mv test.{txt,old.txt}
 test.txt -> test.old.txt

13. 指定時間にコマンドを実行します。 1回限りのタスクです。

$ echo “ls -l” | at midnight

14. リモートファイルとローカルファイルを比較する

$ ssh user@host cat /path/to/remotefile | diff /path/to/localfile –

15. ホストの接続数をグラフ化します

$ netstat -an | grep ESTABLISHED | awk ‘{print $5}’ | awk -F: ‘{print $1}’ | sort | uniq -c | awk ‘{ printf(“%s\t%s\t”,$2,$1) ; for (i = 0; i < $1; i++) {printf(“*”)}; print “” }’

16. 最も頻繁に使用するコマンドのリスト

$ history | awk ‘{a[$2]++}END{for(i in a){print a[i] ” ” i}}’ | sort -rn | head

17. ネットワークサービスのアクティビティをリアルタイムで

lsof -i

18. 懐かしのSLコマンドを実行する

$ brew install sl
$ alias ls='sl -aF'
$ sl

sl.gif

19. 急にスターウォーズがみたくなった

$ brew install telnet
$ telnet towel.blinkenlights.nl 23

starwars.gif

まとめ

以上、つかえるかもしれないコマンド集でした。
これからも役に立つかもしれないコマンドを集めたいと思います。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0