前提:使用mac学习sed命令的时候,有的命令在mac下报错,如下图:

为了解决上面的问题,具体操作如下:
1.首先安装homebrew
(1)下载brew_install.rb这个文件
链接:https://pan.baidu.com/s/1cOeiaA6Z6vb73g3OiCeiZQ 密码:nrc7,我是下载后直接放在Downloads中的
(2)控制台输入
ruby /Users/zhangyu/Downloads/brew_install.rb
会出现如下内容


(3)当出现上面截图内容的时候,准备换源
依次输入
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
brew update

2.重新开启一个终端
(1)输入
brew install gnu-sed
alias sed=gsed

(2)再输入sed命令
sed -e '4 a new line' test.txt
cat test.txt

看到new line插到第4行的后面,证明这个问题解决了。
上面的内容参考文章:https://blog.csdn.net/zbc415766331/article/details/104128351/
网友评论