How to do a non-case sensitive search and keep the case correct in the output

I’m trying to search a configuration file on our machines - the problem is that in some cases, the option is in upper case, others it’s in lower case. My first try:

(concatenation of substrings separated by " " of it) of 
(substrings after "servername" of it as lowercase ) of (lines of file "c:/users/ibm_admin/documents/dsm.sys") whose (it as lowercase starts with "servername" as lowercase );
(concatenation of substrings separated by " " of it) of
(substrings after "SERVERNAME" of it as uppercase ) of (lines of file "c:/users/ibm_admin/documents/dsm.sys") whose (it as lowercase starts with "servername" as lowercase )

The problem is - I want to keep the case of the output as it is in the file. The output above has the lines returned by the top part as all lower case, the bottom returns all upper case. Two issues: (1) the devices all have both upper and lower cases. (2) how to handle mixed case entries - like “ServerName”

Thanks.

Could you elaborate on the use case a bit? The way I’m seeing it, is it looks like you have one giant text file containing the dsm.opt options file for all servers, with each line starting with the name of the server for which it applies - something like

 server1 TSM_SERVER tsm-server.mydomain.com
 server1 TSM_PORT 1500
 server2 TSM_SERVER offsite-tsm-server.mydomain.com
 server2 TSM_PORT 1433

If I’m seeing that correctly, I think what you want is something like

q: concatenation "%0d%0a" of ("server1 TSM_SERVER tsm-server.mydomain.com"; "TEST"; "SerVer1 TSM_PORT 1500"; "server2 TSM_SERVER offsite-tsm-server.mydomain.com"; "server2 TSM_PORT 1433") whose (preceding text of first " " of it as lowercase = "SERVER1" as lowercase)
A: server1 TSM_SERVER tsm-server.mydomain.com
A: SerVer1 TSM_PORT 1500
T: 0.073 ms

q: concatenation "%0d%0a" of (lines of file "X") whose (preceding text of first " " of it as lowercase = hostname as lowercase)

There will be variations on that based on how the file content is formatted; for instance if the line doesn’t begin with the hostname, and the hostname is somewhere in the middle, you may need to resort to regular expressions.

Looks like that will get me going in the right direction. Thanks for your help!

There are a bunch of related analyses on BigFix.Me already that you should check out:

There is a bunch of other content as well.