Macのsed & awkはBSD UNIXの物が標準でインストールされています。ひょんな事からsed & awkを勉強しようと思い立った矢先、書籍やWebの情報はGNUブランドのsed & awkの情報が圧倒的に多いことが分かりました。MacでもGNUブランドのsed & awkを利用するための設定を備忘録にまとめておこうと思います。
2023/5/17 最新のGNU Sed, GNU AWKに対応した情報に更新しました.
sed
参考記事より、まずHomebrewでgsedをインストールします。
brew install gnu-sed
.bash_profile
にPATH
を書き込み、有効化します。
echo 'export PATH="(brew --prefix)/opt/gnu-sed/libexec/gnubin/:$PATH"' >> ~/.bash_profiile
source ~/.bash_profile
$ sed --version
sed (GNU sed) 4.8
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jay Fenlason, Tom Lord, Ken Pizzini,
Paolo Bonzini, Jim Meyering, and Assaf Gordon.
This sed program was built without SELinux support.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
awk
sedと同様の方法で設定出来ます。
brew install gawk
.bash_profile
にPATH
を書き込み、有効化します。
echo 'export PATH=(brew --prefix)/opt/gawk/libexec/gnubin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
$ awk --version
GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0, GNU MP 6.2.1)
Copyright (C) 1989, 1991-2021 Free Software Foundation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.