Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
rubenfasilva
Contributor
Contributor

extract all occurrences from txt file

Hello.

I have one

unstructured

txt file with several occurrences that I want to extract and save to another file.

For example, let's say that we have this text

: "I want to get file1.pdf and file2.pdf" - All I need is to have all the

occurrences that contains *.pdf" and save them in to a new file row by row like this:

file1.pdf

file2.pdf

Is this possible?

Thank you so much!

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi

Read the file as a string using tFileInputRaw, and then extract the file name from the string using regex, for details, see below:

0695b00000YBdvTAAT.png0695b00000YBdviAAD.png0695b00000YBdvsAAD.png0695b00000YBdvxAAD.png 

MyRoutine codes:

 

package routines;

 

import java.util.regex.*;

 

import java.util.Calendar;

import java.util.Date;

 

 

public class MyRoutine {

 

 

static Pattern pattern=Pattern.compile("\\s[\\d\\w]+\\.pdf");

static Matcher matcher=null;

static String result="";

   

  public static String ExtractFileName(String inputData) {

   matcher=pattern.matcher(inputData);

  

    while (matcher.find()) {

       if (result.equals("")){

       result=matcher.group();

       }else{

       result=result+","+matcher.group();

       }

  }

    return result;

     

  }

   

}

 

 

Hope it helps you!

 

Regards

Shong

View solution in original post

2 Replies
Anonymous
Not applicable

Hi

Read the file as a string using tFileInputRaw, and then extract the file name from the string using regex, for details, see below:

0695b00000YBdvTAAT.png0695b00000YBdviAAD.png0695b00000YBdvsAAD.png0695b00000YBdvxAAD.png 

MyRoutine codes:

 

package routines;

 

import java.util.regex.*;

 

import java.util.Calendar;

import java.util.Date;

 

 

public class MyRoutine {

 

 

static Pattern pattern=Pattern.compile("\\s[\\d\\w]+\\.pdf");

static Matcher matcher=null;

static String result="";

   

  public static String ExtractFileName(String inputData) {

   matcher=pattern.matcher(inputData);

  

    while (matcher.find()) {

       if (result.equals("")){

       result=matcher.group();

       }else{

       result=result+","+matcher.group();

       }

  }

    return result;

     

  }

   

}

 

 

Hope it helps you!

 

Regards

Shong

rubenfasilva
Contributor
Contributor
Author

Works!

Thank you so much