DebugFactor.com | Forum

How to remove empty lines from a text or csv file using ansible

I have a report which is generated using Ansible which has a lot of empty lines in between. Please let me know how to remove the empty lines from the file.

You can use the lineinfile module in ansible to achieve this.
Please see code below.

- name: Remove empty lines from a file
  lineinfile:
   path: "/tmp/myfile"
   state: absent
   regexp: '^\s*$'

Hope this helps.