title: Python - extract and modify a file path in all files in a directory in linux
body: <p>I have files .sh files and .json files in which there are file paths given to point to a specific directory, but I should keep on changing the file path, depending on where my python scipt is run.</p>
  
  <p>eg:content of one of my .sh file is 
   "cd /home/aswany/BotStudioInstallation/databricks/platform/databricksastro"</p>
  
  <p>and I should change the file path via python code where the following path </p>
  
  <p>"/home/aswany/BotStudioInstallation/" keep on changing depending on where databicks is located,</p>
  
  <p>I tried the following code:</p>
  
  <pre><code>replaceAll(str(self.currentdirectory)+
      "/databricks/platform/devsettings.json",
      "/home/holmes/BotStudioInstallation",self.currentdirectory)
  </code></pre>
  
  <p>and function  replaceAll is:</p>
  
  <pre><code>def replaceAll(self,file,searchExp,replaceExp):
       for line in fileinput.input(file, inplace=1):
           if searchExp in line:
              line = line.replace(searchExp,replaceExp)
           sys.stdout.write(line)
  </code></pre>
  
  <p>but above code only replaces a line 
   "<code>home/holmes/BotStudioInstallation</code>" to the current directory I am logged in,bt it cannot be sure that "<code>home/holmes/BotStudioInstallation</code>" is the only possibility it keep on changing like "<code>home/aswany/BotStudioInstallation</code>","<code>home/dev3/BotStudioInstallation</code>" etc ,I thought of regular expression for this.</p>
  
  <p>please help me</p>