Find Regexp and replace expression for CSV file starting with $
<p>I need an Regexp and Replace expression to capture contents from CSV file. My CSV file starts like this.</p>

<p>Example- expression should find key name "FC_host" in my CSV file and replace with different value.</p>

<pre><code>$TH_appName=tuipatthcrfh3320
#$TH_host=10.145.129.75
$TH_host=10.145.129.75
$TH_casPort=8500;
$TH_eacPort=8888;
$FC_appName=tuipatfc3320;
#$FC_host=10.145.129.75
$FC_host=10.145.129.75
$FC_casPort=8500;
$FC_eacPort=8888;
</code></pre>

<p>Below is my code. This code works but has few issues.Kindly help me on this.Moreover I am using regexp and replace so that I need to update them in remote server.</p>

<pre><code>    ---
  - hosts: local
    vars:
      properties:
      - { name: "TH_appName", value: "10.0.1" }
    tasks:
      - name: Find and Replace
        replace:
          dest: /etc/ansible/kalyan-tui/example.csv
          regexp: '(.*){{ item.name }}=(.*);'
          replace: '\1{{ item.name }}={{ item.value }};'
         # state: present
        with_items:
          - "{{ properties }}"
</code></pre>

<pre><code>with open('items.csv', 'r')as file:
for row in file:
    print row.replace('TH_host', 'Something else')

&gt;&gt;$TH_appName=tuipatthcrfh3320
&gt;&gt;#$Something else=10.145.129.75
&gt;&gt;$Something else=10.145.129.75
&gt;&gt;...
</code></pre>

<p>You don't need regex unless you need to use the regular expressions such as a number of digits or a certain number of spaces. Regex is very expensive and therefore should be <a href="http://stackoverflow.com/questions/1782586/speed-of-many-regular-expressions-in-python">avoided</a> if possible.</p>

python ansible ansible-playbook ansible-2.x