Excluding "New line" character from text (hosts) file

Hi,
i have a property that shows all “extra” lines of the hosts line.
this works great, except when i have a new line at the end of the hosts file, it shows it as a result, hence giving me incorrect readings.
i was able to exclude the “usual suspects” (line starting with # or with 127.), but how can i exclude empty lines? (only CRLF) - example below:

q: lines whose ((it does not start with "#") AND (it does not start with "127.") AND (it does not start with " ")) of file (pathname of system folder & "\drivers\etc\hosts")
A: 
A: 80.80.80.80         SomeHostName
T: 1.108 ms
I: plural file line

I also tried excluding the escape sequence for EOL (it does not start with “%0d%0a”) but it was unsuccessful.

Would adding a length of it > 0 perhaps work?

q: lines whose ((it does not start with "#") AND (it does not start with "127.") AND (it does not start with " ") and (length of it > 0)) of file (pathname of system folder & "\drivers\etc\hosts")

1 Like

You can exclude blank lines by doing the following:

(it as trimmed string) whose(it != "") of lines of files

Like this:

unique values of (it as trimmed string) of lines whose (it does not start with "#" AND it as trimmed string does not equal "") of files "hosts" of ( folders "/private/etc" ; folders "/etc" ; folders "C:\Windows\System32\drivers\etc" ; folders "C:\Windows\sysnative\drivers\etc" )

Note: the above will work for ALL operating systems. The plural folders will collapse down to only the one that exists on any given platform.

Related:

3 Likes

A wizard, like always :slight_smile:

Thanks!