升级我的 Mac OS 安装后,一些以前的sed
命令对我来说不起作用:
GMC03-calculations $echo $line_no
849
GMC03-calculations $cat corr.in
269 # number of clusters
845 # number of configurations
clusters
...
...
我想将 845(这不是一个常数)替换为$line_no
(在本例中为 849)
GMC03-calculations $sed -i '' 's/^[.0-9]* # number of configurations$/'"$line_no"' # number of configurations/' corr.in
sed: can't read s/^[.0-9]* # number of configurations$/849 # number of configurations/: No such file or directory
以下命令以前有效,但现在不行......非常奇怪......我已经使用 home-brew 安装了 sed.....G
MC03-calculations $brew install sed
Error: No available formula with the name "sed"
==> Searching for similarly named formulae...
These similarly named formulae were found:
gnu-sed ✔ libxdg-basedir minised ssed
To install one of them, run (for example):
brew install gnu-sed ✔
==> Searching taps...
These formulae were found in taps:
Caskroom/cask/focused Caskroom/cask/licensed Caskroom/cask/marsedit Caskroom/cask/physicseditor Caskroom/cask/subclassed-mnemosyne
To install one of them, run (for example):
brew install Caskroom/cask/focused
知道会发生什么吗?谢谢。
答案1
我解决了!通过删除以下''
内容-i
:
sed -i '' 's/^[.0-9]* # number of configurations$/'"$line_no"' # number of configurations/' corr.in
就像这样,一切又恢复正常了:
sed -i 's/^[.0-9]* # number of configurations$/'"$line_no"' # number of configurations/' corr.in
一切似乎都很完美