Find a value separated from keyword by either tab or space

(imported topic written by jeremytoo)

I’m trying to pull a value out of a file. The problem is, the value can appear after either a tab or a space.

My simplified relevance so far is this:

following texts of first " " of lines whose (it contains “KEYWORD”) of file “/tmp/foo”

this works GREAT when there’s a space, but it doesn’t find a value that has a tab separating KEYWORD and the value

alternately, I can do

following texts of first “%09” of lines whose (it contains “KEYWORD”) of file “/tmp/foo”

and I find any lines which are separated by tabs. But it misses those that are separated by spaces.

Short of building a big old IF statement to see if the line is separated by tabs or spaces, and pulling the correct value in that event, is there a way to basically say:

following texts of first WHITESPACE of lines whose (it contains “KEYWORD”) of file “/tmp/foo”

?

(imported comment written by NoahSalzman)

This will work if your files never have non-whitespace characters just to the left of your KEYWORD.

“KEYWORD” & concatenation of following texts of first “KEYWORD” of (lines whose (it contains “KEYWORD”) of file “/tmp/foo”)

(imported comment written by jeremytoo)

well, that’s close, but I’m trying to get just the value to the right of KEYWORD.

e.g. if it says

KEYWORD 4

or

KEYWORD%095

I want to just get a 4 or 5 respectively.

your sample code gives me either:

“KEYWORD 4”

or

“KEYWORD%095”

(depending on which of the top two values it sees)

This is why I was trying to break on a " " or “%09”

I’ve been trying to make:

following texts of first (regex "

%09

") of lines whose (it contains “KEYWORD”) of file “/tmp/foo” work – but can’t quite figure out if that’s even possible or not

(imported comment written by NoahSalzman)

Right… I misread your intent. How about:

concatenation of substrings separated by “%09” of following texts of first “KEYWORD” of (lines whose (it contains “KEYWORD”) of file “/tmp/foo”) as trimmed string

(imported comment written by Tingram91)

try this:

(if it starts with " " then following text of first " " of it else if it starts with “%09” then following text of first “%09” of it else nothing) of (lines whose ((it as string starts with " " AND it as string as lowercase contains “KEYWORD”) OR (it as string starts with “%09” AND it as string as lowercase contains “KEYWORD”)) of file “/tmp/foo”)

(imported comment written by jeremytoo)

with the help of another friend, I got it to work:

(following texts of firsts (" “;”%09") of it) of lines whose (it contains “KEYWORD”) of file “/tmp/foo”

thanks guys!

I really didn’t care whether the file broke on tabs or spaces – I just wanted the value after whatever the separation character was.