Data Infrastructure Management Software Articles and Resources

Workflow example: Remove blank lines, lines with just whitespace, and beginning whitespace of each line from /etc/hosts

Simple workflow that contains a single command that backs up [/vol/vol0]/etc/hosts to [/vol/vol0]/etc/hosts.wfabak then overwrites [/vol/vol0]/etc/hosts, removing any blank lines or any lines that only contain whitespace, as well as beginning whitespace of each line.


(Designed for 7-mode.)


Updated.  Seems Read-NaFile reads all lines as a single string, so regular expressions treat the entire file as one line.  Doh!


Update 2:  More important than removing blank lines was removing the whitespace before the IP address of each line.





The NetApp Community is a public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available.

In accordance with our Code of Conduct and Community Terms of Use, DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information (PII)
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.


Hi Dave,

   I tried working on this Automation to test the functionality on a lab filer before executing in our environment (330+ NTAP IT filers) . It did created a backup file of hosts /vol/vol0/etc/hosts.wfabak but did not remove the blanks lines and leading white spaces.

Any comments.



Hi Manish,

Thanks for letting me know about your experience.  Please try the updated version.  There was a problem in the first version.



Great stuff Dave.  Nice work cranking this out!

All Community Forums