3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

zshAdvent Calendar 2014

Day 11

zshでgrepのようなことをする

Posted at

zsh で簡易 grep 的なことができたので、紹介します。

実行例

${name:#pattern}(M) フラグを組み合わせると配列から glob pattern にマッチしたものだけ抜き出せます。

% echo ${(FM)${(f)"$(< /etc/hosts)"}:#*local*}
127.0.0.1       localhost
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet

(M) フラグなしだと grep -v のようにマッチしなかったものだけが残ります。

% echo ${(F)${(f)"$(< /etc/passwd)"}:#*:[1-8]*}
root:x:0:0:root:/root:/bin/bash
news:x:9:9:news:/var/spool/news:/bin/sh

詳細な解説は blog を参照してください。

3
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?