前提:使用mac學(xué)習(xí)sed命令的時(shí)候,有的命令在mac下報(bào)錯(cuò),如下圖:

為了解決上面的問題,具體操作如下:
1.首先安裝homebrew
(1)下載brew_install.rb這個(gè)文件
鏈接:https://pan.baidu.com/s/1cOeiaA6Z6vb73g3OiCeiZQ 密碼:nrc7,我是下載后直接放在Downloads中的
(2)控制臺(tái)輸入
ruby /Users/zhangyu/Downloads/brew_install.rb
會(huì)出現(xiàn)如下內(nèi)容


(3)當(dāng)出現(xiàn)上面截圖內(nèi)容的時(shí)候,準(zhǔn)備換源
依次輸入
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.重新開啟一個(gè)終端
(1)輸入
brew install gnu-sed
alias sed=gsed

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

看到new line插到第4行的后面,證明這個(gè)問題解決了。
上面的內(nèi)容參考文章:https://blog.csdn.net/zbc415766331/article/details/104128351/