Resolv.conf nameserver and search string,

I have this statement to print the IP and DNS names in the one line for each server.

if (exists file “/etc/resolv.conf”)
then concatenation " " of (following texts of firsts “nameserver” of lines starting with “nameserver” of file “/etc/resolv.conf”) as trimmed string & “,”
, (following texts of firsts “search” of lines starting with “search” of file “/etc/resolv.conf”) as trimmed string
else nothing

but this statement fails if the “search” don’t exist in the resolv.conf, and if “search or namserver” has some spaces in front of the statement in the resolv.conf.
How do i get the IP and search string in one line irrespective of spaces or positioning or not exist in the resolv.conf?

This query gives me the result in this way

concatenation " " of (lines of file “/tmp/1.conf”) whose (it contains regex “nameserver|search” AND it does not contain “#” ) as trimmed string

server_name search a.b.c.d w.x.y.z nameserver 1.2.3.4 nameserver 5.6.7.8

How do i remove “search” and “nameserver” so that I can get " 1.2.3.4 5.6.7.8 a.b.c.d w.x.y.z " in one line, ip address fist and dnsname?

You should be able to combine your two queries to get the result you’re looking for. The 2nd one ensures you are only looking at lines that contain the right strings, so then you can use ‘following texts of firsts “nameserver” of it’ without worries of error.

I used this query this time.

( concatenation ", " of substrings separated by “search” of it) of ( concatenation " " of substrings separated by “nameserver” of it ) of concatenation " " of unique values of (it as string as trimmed string) of (lines of file “/etc/resolv.conf”) whose ( it contains regex “nameserver|search” AND it does not contain “#” ) as trimmed string

resolv.conf is not consistent across our 10K servers. some of them has space(s) in front of the “search” or “nameserver” or some them don’t have “search” . I just want to have the result to be printed in 1 line with “server_name DNSIPaddress1 , DNSfqdn” so that it will be easy to read or fiter the data from CSV.

If the files are not consistent, you’re probably better off using regex. If you can figure out the right regex stmt to replace <parenthesized regex string>, you would use:

parenthesized part 1 of it & parenthesized part 3 of it & parenthesized part 2 of it of (matches (regex "<parenthesized regex string>") of it as string) of lines whose (it contains regex “nameserver|search” AND it does not contain “#” ) of files "/etc/resolv.conf"