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

by bdave Former NetApp Employee on ‎2013-03-19 05:40 PM - edited on ‎2014-09-25 03:35 PM by allison Former NetApp Employee

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.

 

Thanks,

Dave

Comments
Member

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.

Regards

Manish

bdave Former NetApp Employee

Hi Manish,

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

Cheers,

Dave

Frequent Contributor

Great stuff Dave.  Nice work cranking this out!

Warning!

This NetApp Community is 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. This includes the rich text editor which is not encrypted for https.

In accordance to 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
  • 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.