Bigfix relevance to read columns of file

I have a file test.txt with the below content:

Filesystem:Type:Mount:ID:State:Enable
/fs1:typ1:yes:123:new:0
/fs2:typ2:no::new:1
/fs3:typ3:yes::old:0

Need to write a relevance to fetch the last column of the above content.
that is:

new 
new
old
(parenthesized parts (5) of (matches (regex "___") of lines of file "test.txt")

I am confused on writing the regex expression.

Do you really need regex?

Regex is powerful and sometimes the only answer, but this appears to be achievable without regex.

following texts of lasts ":" of lines whose (it starts with "/") of file "c:\trn\test1.txt"

2 Likes

@trn, Thanks for your reply :slight_smile:

However, I missed to add the last column. Post edited. Kindly check.
Also, I need to used the “parenthesized” relevance itself.

So is this an exam/course question? I can think of no real-world situation where the method is prescribed.

Suggest you look at a regex site such as https://www.regular-expressions.info/

1 Like

I agree with @trn that regex is a bit heavy for this use case, but I also love teaching…
So here is a Regex that does what you were looking for.

^ start beginning of string

([^:]*) any number of “not a colon” characters as a parenthesized capture group.
: the colon that separates…
repeat the pattern once per column

q: parenthesized parts (5) of matches (regex "^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)") of lines of file "C:\Tools\QNA\QNA10.0.3.66\file.txt"
A: State
A: new
A: new
A: old

And to get rid of State, we might add the slash to the front, next to the front anchor.

q: parenthesized parts (5) of matches (regex "^/([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)") of lines of file "C:\Tools\QNA\QNA10.0.3.66\file.txt"
A: new
A: new
A: old

Seems like you should be able to use {5} to repeat that ([^:]*): pattern, but I could not get it to work that way.

And yet another approach, using substrings and tuple string items (this one is very popular with BigFixers)

q: (tuple string items 4 of concatenations ", " of substrings separated by ":" of it) of lines whose (it starts with "/") of file "C:\Tools\QNA\QNA10.0.3.66\file.txt"
A: new
A: new
A: old
2 Likes

Thanks a lot @brolly33 :slight_smile:
You are one of the best instructor :slight_smile:

1 Like