Skip to main content
Attempt to make sense of the run-on sentences. Use punctuation!
Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

how to replace Replace a string in a file and overwrite the file?

I wrote my script using the the folder ~/deleteddirectory ~/deleted (itsit's a long script). after using ""~/deleted""~/deleted for the whole script. I want to let the user choose the directory by putting the path in ~/.rm~/.rm.cfg.cfg

myMy file starts like this:

#!/bin/bash

defaultpath=~/deleted

if [ -s ~/.rm.cfg ]
then
    defaultpath=$(head -1 ~/.rm.cfg)
fi

I need to replace every ""~/deleted""~/deleted with ""$defaultpath""$defaultpath in my script. isIs there a way to do it in command line such that it saves and replaces the original file?

I can't get either perl or sed to work.

how to replace a string in a file and overwrite the file?

I wrote my script using the the folder ~/deleted (its a long script) after using ""~/deleted"" for the whole script I want to let the user choose the directory by putting the path in ~/.rm.cfg

my file starts like this

#!/bin/bash

defaultpath=~/deleted

if [ -s ~/.rm.cfg ]
then
    defaultpath=$(head -1 ~/.rm.cfg)
fi

I need to replace every ""~/deleted"" with ""$defaultpath"" in my script. is there a way to do it in command line such that it saves and replaces the original file?

I can't get either perl or sed to work

Replace a string in a file and overwrite the file

I wrote my script using the the directory ~/deleted (it's a long script). after using ~/deleted for the whole script. I want to let the user choose the directory by putting the path in ~/.rm.cfg.

My file starts like this:

#!/bin/bash

defaultpath=~/deleted

if [ -s ~/.rm.cfg ]
then
    defaultpath=$(head -1 ~/.rm.cfg)
fi

I need to replace every ~/deleted with $defaultpath in my script. Is there a way to do it in command line such that it saves and replaces the original file?

I can't get either perl or sed to work.

edited title
Link
lonewarrior556
  • 2.2k
  • 5
  • 17
  • 13

how to replace a string in a file and over rideoverwrite the file?

Source Link
lonewarrior556
  • 2.2k
  • 5
  • 17
  • 13

how to replace a string in a file and over ride the file?

I wrote my script using the the folder ~/deleted (its a long script) after using ""~/deleted"" for the whole script I want to let the user choose the directory by putting the path in ~/.rm.cfg

my file starts like this

#!/bin/bash

defaultpath=~/deleted

if [ -s ~/.rm.cfg ]
then
    defaultpath=$(head -1 ~/.rm.cfg)
fi

I need to replace every ""~/deleted"" with ""$defaultpath"" in my script. is there a way to do it in command line such that it saves and replaces the original file?

I can't get either perl or sed to work