LoginSignup
2
2

More than 5 years have passed since last update.

いつの間にか追加してた長いワンライナーとその時のテク

Posted at

アドベントカレンダー企画で、いつの間にか追加していたワンライナーを載せます。
あと、便利な覚え書き程度のテクを載せます。

gitのrootディレクトリに戻る。

標準のように多用している。

function cdg() { builtin cd `git rev-parse --show-toplevel`; return 0;}

議事録から日付を抜き出す。

find /path/議事録/`date "+%Y_%m_%d"`*.html -type f -print0 | xargs -0 grep '.\{1,2\}月.\{1,2\}日' | pup "text{}" | grep -v '^\s*$' | tail -1 | cut -c 1-20

議事録の最後の行を見る。

find . -type f -name "*議事録*" -not -name "trashed*" | tail -1 | xargs -I% cat '%'

今日の天気

livedoor天気を利用している。。APIにやさしい版はこちらhttps://qiita.com/benridane/items/6ebfe45d8abcc497d09d

curl -s http://weather.livedoor.com/forecast/webservice/json/v1\?city\=270000 | jq -r '.forecasts[0].telop'

簡単なテク解説

  • pup: go製のhtmlパーサ。https://github.com/ericchiang/pup
    • パーサーはxmllintなどあるが、いろんな環境で動くものとしておススメしたい。
  • jq: 高機能パーサ。JSONパーサ。https://stedolan.github.io/jq/
    • pup "json{}"でjsonに変換してjqで処理することもできる。
  • find: ファイル検索。
    • -not -name "trashed*"でファイルを除外できる。
  • xargs: -0を付けるとヌル文字対応になる。
    • xargs -I% cat '%'で確かスペース対策で出力できる。
  • grep: grep -v '^\s*$'で空行除外ができる。

以上、ちょっとしたテクでした。

2
2
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
2
2