# removing blank lines after all lines start with specific string

**URL:** <https://forum.ansible.com/t/removing-blank-lines-after-all-lines-start-with-specific-string/28817>\
**Category:** Ansible Project\
**Created:** [October 18, 2018, 7:47am UTC](https://forum.ansible.com/t/removing-blank-lines-after-all-lines-start-with-specific-string/28817 "2018-10-18T07:47:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shlomit\_Afgin](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Shlomit\_Afgin](https://forum.ansible.com/u/Shlomit_Afgin)\
**Post date:** [October 18, 2018, 7:47am UTC](https://forum.ansible.com/t/removing-blank-lines-after-all-lines-start-with-specific-string/28817/1 "2018-10-18T07:47:03Z")

</div>

HI,  
Is there any way to remove from a file, all blank lines that exist after line start with specific string?

for example:

Remove all blank lines after lines start with XXX1

`  
XXX1bla bla bla

hjshfgdfg  
gdfsgdsgdf  
gsdfgd

XXX1 blu bluu blu

dfjgljfd  
gfdgds

`

will be:

`  
XXX1bla bla bla  
hjshfgdfg  
gdfsgdsgdf  
gsdfgd

XXX1 blu bluu blu  
dfjgljfd  
gfdgds

`

---

<div class="post-metadata">

**Author:** ![aakanksha.jain](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@aakanksha.jain](https://forum.ansible.com/u/aakanksha.jain)\
**Post date:** [October 18, 2018, 8:48am UTC](https://forum.ansible.com/t/removing-blank-lines-after-all-lines-start-with-specific-string/28817/2 "2018-10-18T08:48:45Z")

</div>

you can write shell script for that and put that code in playbook.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 18, 2018, 3:22pm UTC](https://forum.ansible.com/t/removing-blank-lines-after-all-lines-start-with-specific-string/28817/3 "2018-10-18T15:22:53Z")

</div>

- replace:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: my\_file  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regexp: '(XXX1.\*)$\s+'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replace: '\1'
