Extract values after colon in a text file

I have an action that is dumping some configuration pairs to a colon delimited text file like this:

Setting1: Value1
Setting2: Value2
Setting3: Value3

I want to run an analysis that does “Find the line in the text file that begins with “Setting3” and extract the text after the colon on the found line” and end up with “Value 3” in my analysis. Ultimately I’ll pull about 2/3 of the lines all as separate proprty in the analysis.

I know this should be easy and I have tried several examples of similar questions on here but none seem to work exactly even if it looks like they should.

1 Like

Try

following texts of firsts ": " of lines starting with "Setting3:" of files "C:\path\to\file.txt"

6 Likes

I’ll throw out there that if you can create the file with key value pairs like an INI file then you could read it like this also.

Setting1=Value1
Setting2=Value2
Setting3=Value3

key “Setting3” of file (“c:\test\myfile.txt”) | “n/a”

I tested this vs Jason’s answer and they both perform the same, so it would probably just be personal preference if you could accommodate both.

3 Likes

Thanks for bringing this up! In fact, I find this approach is not well-known, but it can work quite well in certain cases. Note that it can also handle file ‘sections’:

Q: lines of file "R:\myfile.txt"
A: [foo]
A: Setting1=Value1
A: Setting2=Value2
A: Setting3=Value3
A: 
A: [bar]
A: Setting1=ValueA
A: Setting2=ValueB
A: Setting3=ValueC

Q: key "Setting3" of section "foo" of file "R:\myfile.txt"
A: Value3

Q: key "Setting3" of section "bar" of file "R:\myfile.txt"
A: ValueC
2 Likes