1

After upgrading my Mac OS install some previous sed commands do not work for me:

GMC03-calculations $echo $line_no 
849
GMC03-calculations $cat corr.in
269 # number of clusters
845 # number of configurations
clusters 
...
...

I would like to replace the 845 (this is not a constant) into $line_no (in this case 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

the following command works previously but not now.... very strange... I have installed sed using home-brew..... 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

Any idea what might be happening? Thank you.

1
  • Please edit your question. This is a very good question and self-solved answer; nice work! But what version of Mac OS X did you have previously and what did you upgrade to? This is most likely all connected to sed version changes so it would be good information to add to the question. – Giacomo1968 Aug 16 '16 at 4:40
1

I solved it! By removing the '' after -i :

sed -i '' 's/^[.0-9]* # number of configurations$/'"$line_no"' # number of configurations/' corr.in

Like this it all works again:

sed -i 's/^[.0-9]* # number of configurations$/'"$line_no"' # number of configurations/' corr.in

Everything seems to work perfect

1
  • What if you had used /usr/bin/sed -i ' ' 's........ ? – fd0 Aug 16 '16 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.