LoginSignup
1
0

More than 5 years have passed since last update.

Unix で非 ASCII 文字を含む行だけを抽出する Tips

Last updated at Posted at 2018-03-16

grep で頑張ろうと思ったけど Perl を使ったほうが楽だった。

非 ASCII 文字を含む行を抽出する

$ cat FILE | perl -ne 'print if /[[:^ascii:]]/'

非 ASCII 文字を含まない (ASCII 文字のみの) 行を抽出する

$ cat FILE | perl -ne 'print unless /[[:^ascii:]]/'

ASCII 文字を含む行と含まない行をそれぞれ別のファイルに出力する

$ cat FILE | perl -ne 'if (/[[:^ascii:]]/) { print STDERR } else { print STDOUT }' 1> ASCII_FILE 2> NON_ASCII_FILE
1
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
1
0