ときおり、ログやテキストファイル内の日本語文字列のみをマスキング(●とかに)置換したいと考える事がある。
そんな時は、sedで以下のようにコマンドを実行すると良いだろう。
LANG=C sed 's/[\x80-\xFF]//g' ファイルPATH
実際に実行した結果がこちら。
[root@test-centos7 ~]# cat' /work/test2.log [2015/09/06 11:00:00] send mail to 'aaaa@aaaaa.co.jp' '田中一郎' [2015/09/06 11:05:00] send mail to 'bbbb@aaaaa.co.jp' '山田二郎' [2015/09/06 11:10:00] send mail to 'cccc@aaaaa.com' and 'cccc@rrrrr.or.jp' '佐藤三郎' [2015/09/06 11:15:00] send mail to 'dddd@ddddddd.com' '天草四郎' [root@test-centos7 ~]# [root@test-centos7 ~]# sed 's/[\x80-\xFF]/●/g' /work/test2.log sed: -e expression #1, char 19: 無効な照合文字です [root@test-centos7 ~]# [root@test-centos7 ~]# LANG=C sed 's/[\x80-\xFF]/●/g' /work/test2.log [2015/09/06 11:00:00] send mail to 'aaaa@aaaaa.co.jp' '●●●●●●●●●●●●' [2015/09/06 11:05:00] send mail to 'bbbb@aaaaa.co.jp' '●●●●●●●●●●●●' [2015/09/06 11:10:00] send mail to 'cccc@aaaaa.com' and 'cccc@rrrrr.or.jp' '●●●●●●●●●●●●' [2015/09/06 11:15:00] send mail to 'dddd@ddddddd.com' '●●●●●●●●●●●●'
![[改訂新版] シェルスクリプト基本リファレンス --#!/bin/shで、ここまでできる (WEB+DB PRESS plus)](http://ecx.images-amazon.com/images/I/41GMyWgQ3cL._SL160_.jpg)