Want to iterate a file and copy the current line if the first field meets criteria - how to do it easily?

So, I have a file that contains several fields separated by a pipe. When deciding whether to copy the current line into a new file, I only want to test to see if the value of the first field matches the value in the first field of the line before it. I can do a File Iterator, but then I cannot take a Substring on the current line up to the first pipe because Substring either requires two indices (starting and ending) or two strings (starting and ending). What I want is to take a substring from index 0 to the first occurrence of the pipe and put that into a variable.

So, I try a CSV iterator. This will work if I set a variable equal to every field value in the line, and then recreate the line with all of the pipes and variables when I want to copy the line to the new file. But I don’t need variables for all of the fields, and it seems like a lot of overhead.

What am I missing? Is there a way to do a File Iterator but find the value of the first field on each line? Or do a CSV Iterator, but set a variable to the entire current line so that I can write that variable to the new file?

After all these years of using and liking Automise, I feel like there is some trick I should be able to use, but I cannot think of what it would be. Any help is appreciated.

I found a workaround using the String Pos action to get the position of the first pipe, then used that as the length of the substring starting with index 0. I still think you should be able to take a substring from the start of the string to a specified character or text within the larger string - but I guess that is an enhancement request.

I think what we lack is a String Split action - but then the question would be what do we do with the results of that split - we lack an array variable type - and if we add the array type then how will actions work with that array.

This is an area of research that we are working on for AT6 (yes, much delayed) - along with ways to do things like work with Json & YAML (ie objects). Creating the variable types needed is not difficult - it’s how we work with them in actions that is the hard part (there are a lot of actions to consider!).

We’re finishing off some much needed infrastructure work (website, store) and once that is done we’ll be doubling down on getting FB9 & AT6 done.

1 Like