find string in text files with the position number ex: position5, position8, etc.,

vullim

New Member
I have a Process where it search for a string in text files and writes the results in excel with the string position, it only gives the first position, I need to get all the positions if string found, is it possible ? as a newbie I am unable to figure this out.. any help much appreciated.

current results:
View attachment 1544494764189.png

Expected Results

View attachment 1544548849544.png

using the below expression to get the position.
 

Attachments

  • 1544495677611.png
    42.6 KB · Views: 40
Last edited:

VJR

Well-Known Member
I have a Process where it search for a string in text files and writes the results in excel with the string position, it only gives the first position, I need to get all the positions if string found, is it possible ? as a newbie I am unable to figure this out.. any help much appreciated.

current results:
View attachment 2762

Expected Results

View attachment 2763

using the below expression to get the position.
View attachment 2765
Did you miss a screenshot? The last two are the same.
 

VJR

Well-Known Member
Hi VJR, I've updated the screenshots, please let me know if you need more details.

Thanks for checking.
Hi vullium,

I am looking for a screenshot that says "using the below expression to get the position."
How are you getting the value in the Position data item? It could be an Instr function but I want to see how have you taken it.
 

sivagelli

Well-Known Member
By design, Instr() returns only the position of first occurrence of search string in the text, if found. If you need multiple occurrences you have to loop thru the Instr() action till the position becomes 0 (zero).

I am assuming that the file data is read into a Data Item (looking at the screenshot of Instr action), and suggesting the below flow-

Have 4 Data Items: Counter, Position, StartByte, ConcatData with initial values as 1, 0, 1, "String Found in Position" respectively
  1. Start
  2. Anchor1
  3. Decision1 Stage with condition Counter =1
    • Yes Path of Decision1
      • Instr Action from Strings VBO
      • Calc Stage to increment Counter. Link this to Decision2
    • No Path of Decision1
      • Calc Stage with expression [Position]+1 stored in StartByte
      • Instr Action from Strings VBO. Link this to the Decision2
  4. Decision2 stage to check if Position is 0 (0 means string not found)
    • Yes Path Decision2
      • Add a Decision3 stage with condition Len([ConcatData]) = Len("String Found in Position")
        • Yes Path of Decision3
          • Calc Stage with expression "String Not Found" Stored in ConcatData
          • Link to End
        • No Path of Decision3
          • Action "Remove Non-word Characters" from Utility Strings VBO
          • Link to End
    • No Path of Decision2
      • Calc Stage with Expression [ConcatData]&[Position]&", "
      • Link this to Anchor1

In the flow there is no Loop Stage, however using Anchors and Decision stages we can simulate looping.

Unfortunately, I cannot share screenshots, if you follow the above steps you should be achieving the required.

Post back how to goes!
 

vullim

New Member
By design, Instr() returns only the position of first occurrence of search string in the text, if found. If you need multiple occurrences you have to loop thru the Instr() action till the position becomes 0 (zero).

I am assuming that the file data is read into a Data Item (looking at the screenshot of Instr action), and suggesting the below flow-

Have 4 Data Items: Counter, Position, StartByte, ConcatData with initial values as 1, 0, 1, "String Found in Position" respectively
  1. Start
  2. Anchor1
  3. Decision1 Stage with condition Counter =1
    • Yes Path of Decision1
      • Instr Action from Strings VBO
      • Calc Stage to increment Counter. Link this to Decision2
    • No Path of Decision1
      • Calc Stage with expression [Position]+1 stored in StartByte
      • Instr Action from Strings VBO. Link this to the Decision2
  4. Decision2 stage to check if Position is 0 (0 means string not found)
    • Yes Path Decision2
      • Add a Decision3 stage with condition Len([ConcatData]) = Len("String Found in Position")
        • Yes Path of Decision3
          • Calc Stage with expression "String Not Found" Stored in ConcatData
          • Link to End
        • No Path of Decision3
          • Action "Remove Non-word Characters" from Utility Strings VBO
          • Link to End
    • No Path of Decision2
      • Calc Stage with Expression [ConcatData]&[Position]&", "
      • Link this to Anchor1

In the flow there is no Loop Stage, however using Anchors and Decision stages we can simulate looping.

Unfortunately, I cannot share screenshots, if you follow the above steps you should be achieving the required.

Post back how to goes!
Hi Siva,

Thanks for taking time to provide some recommendations, I've been trying to implement as per your suggestions, but couldn't succeeded, I am sill a newbie so still struggling. it would be good if there is possibility to share screenshots but you stated that's not possible so.. looking around to figure this out..........
 

sivagelli

Well-Known Member
Thanks for exploring the solution i suggested.
Let me know where you are struggling and share screenshots. I may attempt to help.
 
By design, Instr() returns only the position of first occurrence of search string in the text, if found. If you need multiple occurrences you have to loop thru the Instr() action till the position becomes 0 (zero).

I am assuming that the file data is read into a Data Item (looking at the screenshot of Instr action), and suggesting the below flow-

Have 4 Data Items: Counter, Position, StartByte, ConcatData with initial values as 1, 0, 1, "String Found in Position" respectively
  1. Start
  2. Anchor1
  3. Decision1 Stage with condition Counter =1
    • Yes Path of Decision1
      • Instr Action from Strings VBO
      • Calc Stage to increment Counter. Link this to Decision2
    • No Path of Decision1
      • Calc Stage with expression [Position]+1 stored in StartByte
      • Instr Action from Strings VBO. Link this to the Decision2
  4. Decision2 stage to check if Position is 0 (0 means string not found)
    • Yes Path Decision2
      • Add a Decision3 stage with condition Len([ConcatData]) = Len("String Found in Position")
        • Yes Path of Decision3
          • Calc Stage with expression "String Not Found" Stored in ConcatData
          • Link to End
        • No Path of Decision3
          • Action "Remove Non-word Characters" from Utility Strings VBO
          • Link to End
    • No Path of Decision2
      • Calc Stage with Expression [ConcatData]&[Position]&", "
      • Link this to Anchor1

In the flow there is no Loop Stage, however using Anchors and Decision stages we can simulate looping.

Unfortunately, I cannot share screenshots, if you follow the above steps you should be achieving the required.

Post back how to goes!
What is the use of Decision3 and Remove non-word characters here? If the position is zero then we can directly say it as "String not found",right?
 

sivagelli

Well-Known Member
Decision3, checks condition Len([ConcatData]) = Len("String Found in Position"). This checks the current value in 'ConcatData' to the initial string which is 'String Found in Position'. If both are equal then it would print string not found, else it would trims additional ',' at the end of strings using the action, which will be added if the position is found in the other part of the flow.

Hope this helps!
 
What input and output should i give in the Remove non word characters stage?
 

Attachments

  • IMG20181218212506.jpg
    478.3 KB · Views: 18
  • IMG20181218221144.jpg
    452.1 KB · Views: 13

sivagelli

Well-Known Member
Input has be the text you want to trim non-alphaneumericals from. Here, I used 'ConcatData' as input has ',' at the end of the string which i wanted to trim.
 

vullim

New Member
I am only getting the first found position, not getting other positions, I have multiple files in a folder and the process getting the first position in each file, but i need all the positions in each file.
 
For getting all the positions of a string in a file follow the #6 in this thread. It will help you to get all the positions.. To find the positions in multiple files.. Get the files in a path using GET FILES action. Then loop through the files and store the result in a collection.. Merge them at last. PFA.
 

Attachments

  • IMG20181221192946.jpg
    444.7 KB · Views: 15
  • IMG20181221192956.jpg
    491.3 KB · Views: 14
Top