How do I compare values of a configuration file, delimited by : or ,

(imported topic written by SystemAdmin)

Instead of using the relevance:

exists file “/opt/sni/unix/etc/bladeinfo” AND exists lines whose ( it contains “HS21” ) of file “/opt/sni/unix/etc/bladeinfo” AND (following text of first “:” of lines whose (it starts with “B:”) of file “/opt/sni/unix/etc/bladeinfo” as version < ")

for File: /opt/sni/unix/etc/bladeinfo

cbcbc005mm

08

uxfit344

HS21

B:1.19

D:1.06

S:1.20

C:1.4.11.43

E:enabled

I want to use a “,” delimited file like this:

cbcbc005mm,08,uxfit344,HS21,1.19,1.06,1.20,1.4.11.43,enabled

I want to use a single line configuration file and read specific positional values to compare in a relevance statement like I do at the top of this post for the multi-line file with B: prefix

To compare the 5th value of 1.19 of the file, what relevance could I use?? Need help

(imported comment written by Lee Wei)

This definitely sounds doable.

There is a “tuple string” keyword that we can use. However, it expects the items to be perfectly separated by a comma and space.

So if you are the creator of the line and can guarantee the comma and space, then the following will work.

q: tuple string items 2 of ("cbcbc005mm, 08, uxfit344, HS21, 1.19, 1.06, 1.20, 1.4.11.43, enabled")
A: uxfit344

That sounds too dangerous, so we can add a little code to first split up the items separated by the commas (substrings separated by), clean up any leading and trailing spaces (trimmed string), then stitch them back with precisely a comma and space (concatenation ", ").

q: tuple string item 3 of concatenation ", " of (it as trimmed string) of substrings separated by "," 
 of "cbcbc005mm, 08,uxfit344, HS21 ,1.19,1.06,1.20,1.4.11.43,enabled"
A: HS21
 
q: (it = "1.19") of tuple string item 4 of concatenation ", " of (it as trimmed string) of substrings separated by "," 
of "cbcbc005mm, 08,uxfit344, HS21 ,1.19,1.06,1.20,1.4.11.43,enabled"
A: True

Lee Wei

(imported comment written by NoahSalzman)

Other ways to do it:

Q: lines of file “/Users/noah/foo.txt”

A: cbcbc005mm,08,uxfit344,HS21,1.19,1.06,1.20,1.4.11.43,enabled

Q: parenthesized part 5 of matches (regex "^(

http://a-zA-Z0-9.

+),(

http://a-zA-Z0-9.

+),(

http://a-zA-Z0-9.

+),(

http://a-zA-Z0-9.

+),(

http://a-zA-Z0-9.

+),(.*)$") of lines of file “/Users/noah/foo.txt”

A: 1.19

Q: preceding texts of first “,” of following texts of first “,” of following texts of first “,” of following texts of first “,” of following texts of first “,” of “cbcbc005mm,08,uxfit344,HS21,1.19,1.06,1.20,1.4.11.43,enabled”

A: 1.19

(imported comment written by SystemAdmin)

All of these are very complex, is there not a simple solution like the perl split command?.

I could create the file with a ", " followed by a space, but that’s not a normal delimiter. What about a “:” same solutions? Does the delimiter have to have a space following the delimiter?

there’s got to be a better way…

(imported comment written by NoahSalzman)

substrings separated by “,”

is pretty much identical to Perl’s

split

command, but you will still need some “ugliness” (as in the posts above) to get at the 5th chunk.

Also, I would argue that my preceding/following example is not so much “complex” as “syntactically inelegant.”

Here is the “split” syntax:

Q: substrings separated by “,” of lines of file “/Users/noah/foo.txt”

A: cbcbc005mm

A: 08

A: uxfit344

A: HS21

A: 1.19

A: 1.06

A: 1.20

A: 1.4.11.43

A: enabled

Q: concatenation “:” of substrings separated by “,” of lines of file “/Users/noah/foo.txt”

A: cbcbc005mm:08:uxfit344:HS21:1.19:1.06:1.20:1.4.11.43:enabled

(imported comment written by SystemAdmin)

So, how would this statement be changed to work with the single line delimited file without the B: before the 1.19 value

exists file “/opt/sni/unix/etc/bladeinfo” AND exists lines whose ( it contains “HS21” ) of file “/opt/sni/unix/etc/bladeinfo” AND (following text of first “:” of lines whose (it starts with “B:”) of file “/opt/sni/unix/etc/bladeinfo” as version < ")

cbcbc005mm,08,uxfit344,HS21,1.19,1.06,1.20,1.4.11.43,enabled

or

cbcbc005mm:08:uxfit344:HS21:1.19:1.06:1.20:1.4.11.43:enabled

(imported comment written by NoahSalzman)

Replace this part:

(following text of first “:” of lines whose (it starts with “B:”) of file “/opt/sni/unix/etc/bladeinfo” as version < ")

With:

((preceding text of first “:” of following texts of first “:” of following texts of first “:” of following texts of first “:” of following texts of first “:” of lines whose (it contains “HS21”) of file “/opt/sni/unix/etc/bladeinfo”) as version < “1.19”)

Change the semi-colons to commas if that is how your line is formatted.

(imported comment written by SystemAdmin)

Q: ((preceding texts of first “,” of following texts of first “,” of following texts of first “,” of following texts of first “,” of following texts of first “,” ) of lines whose (it contains “HS21” ) of file “/opt/sni/unix/etc/bladeinfo1”) as version < ")

E: The operator “first” is not defined.

Q: ((preceding texts of first “,” of following texts of first “,” of following texts of first “,” of following texts of first “,” of following texts of first “,” of lines whose (it contains “HS21” ) of file “/opt/sni/unix/etc/bladeinfo1”) as version < “1.19”)

E: A singular expression is required.

(imported comment written by SystemAdmin)

Got it!!!

Q: ((preceding text of first “,” of following text of first “,” of following text of first “,” of following text of first “,” of following text of first “,” of line whose (it contains “HS21” ) of file “/opt/sni/unix/etc/bladeinfo1”) as version < ")

A: False

T: 196

Q: ((preceding text of first “,” of following text of first “,” of following text of first “,” of following text of first “,” of following text of first “,” of line whose (it contains “HS21” ) of file “/opt/sni/unix/etc/bladeinfo1”) as version = “1.19”)

A: True

T: 199

(imported comment written by SystemAdmin)

To Noah, I got a tuple function to work on a “:” delimited file (Thanks to Jimmie Jones (BigFix)

For my single line configuration file: cbcbc005mm:08:uxfit344:HS21:1.19:1.06:1.20:1.4.11.43:enabled

exists file “/opt/sni/unix/etc/bladeinfo” and (tuple string item 4 of concatenation ", " of substrings separated by “:” of line whose ( it contains “HS21”) of file “/opt/sni/unix/etc/bladeinfo” as version < ")

This allows easy re-use to compare any alue in the file just by changing position number starting with 0

Thanks again for your help…

Jeff

(imported comment written by NoahSalzman)

Excellent! I like that approach better (yay Jimmie)… “tuple string” is actually something I haven’t used much and this is a perfect spot to employ it.

(imported comment written by MarkA.Stevens)

How to parse /etc/passwd which is delimited by colons (:slight_smile: This allows you to:

  1. Get any text between colons.

  2. Get one or more parts of a delimited record, colons, commas, whatever you don’t want. Example: replace

:

with

,

I Hope This Helps

Q: (parenthesized part 1 of it ; parenthesized part 7 of it) of (matches (regex "

(

:+):frowning:

:

+):frowning:

:

+):frowning:

:

+):frowning:

:

+):frowning:

^:

+):(.*)$") of (lines of file “/etc/passwd” as string))

A: root

A: /sbin/sh

A: adm

A:

A: bigfix

A: /usr/bin/ksh

A: stevenam

A: /usr/bin/bash

T: 20602869

I’m trying to use this to find one file (for starters) and getting what seems to be inconsistent results between two Unices and two different versions of the dubugger. I know, two equations and two unknowns makes for a difficult solution. I’m stuck with 7.2.x for Solaris, but the 255 character limit is driving me nuts, so I thought I’d attempt to solve the problem on Linux, which doesn’t have that problem in the debugger.

Note: Not every account/userid has .profile or other files I will be searching for.

  1. Solaris:

-bash-3.00$ su -

Password:

Oracle Corporation SunOS 5.10 Generic Patch January 2005

Running BES Client:

PKGINST: BESagent

NAME: BigFix Agent

VERSION: 7.2.4.60

  1. uname -a

SunOS sonny 5.10 Generic_142910-17 i86pc i386 i86pc

  1. startqna

BESClientActionMastheadPath not set, using /etc/opt/BESClient/actionsite.afxm

Q: (files “.profile” of folder it) of ((parenthesized part 6 of it) of (matches (regex "

(

:+):frowning:

:

+):frowning:

:

+):frowning:

:

+):frowning:

:

+):frowning:

^:

+):(.*)$") of (lines of file “/etc/passwd” as string)) as string)

A: //.profile

A: //.profile

A: //.profile

A: //.profile

A: //.profile

A: //.profile

A: //.profile

A: //.profile

A: //.profile

A: /export/home/bigfix/.profile

A: /export/home/dadrian/.profile

A: /export/home/stevenam/.profile

T: 7393527

  1. Red Hat Linux

$ sudo su -

Password:

Sorry, try again.

Password:

Running BES Client:

Name : BESAgent Relocations: (not relocatable)

Version : 8.0.584.0 Vendor: BigFix, Inc.

root@clifford ~

uname -a

Linux clifford.localdomain 2.6.18-164.el5 #1 SMP Thu Sep 3 02:16:47 EDT 2009 i686 i686 i386 GNU/Linux

root@clifford ~

startqna

BESClientActionMastheadPath not set, using /etc/opt/BESClient/actionsite.afxm

Q: (files “.profile” of folder it) of ((parenthesized part 6 of it) of (matches (regex "

(

:+):frowning:

:

+):frowning:

:

+):frowning:

:

+):frowning:

:

+):frowning:

^:

+):(.*)$") of (lines of file “/etc/passwd” as string)) as string)

A: /root/.profile

E: Singular expression refers to nonexistent object.

T: 7193