TSV String, Filter by Text
TSV String, Filter by Text
Filters TSV string with any search text. Only lines that contain the search text in the specified column are output. If you want an OR search with multiple texts, specify them as a comma-separated list such as “USA,U.S.,United States”.
Configs
  • A: Select STRING DATA for TSV String *
  • B-target: Set Column ID to be Searched (eg “0” ) *#{EL}
  • B-texts: Set Search Texts (eg “USA” “USA,U.S.” ) *#{EL}
  • C: Select STRING DATA for Filterd TSV (update) *
Script (click to open)

// (c) 2021, Questetra, Inc. (the MIT License)
// Notes:
// Cannot specify search terms that contain a comma.
// For "AND search", try to place this Automated Step serially.
// Special characters in search text settings have no meaning (literal string).
// Notes(ja):
// カンマを含む検索語は指定できません
// "AND検索" は自動工程の直列配置をお試しください
// 検索テキスト設定の特殊文字に意味はありません(リテラル文字列)


//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA     = configs.get( "conf_DataIdA" ) + "";     // config required
const targetColId = configs.get( "conf_TargetColId" ) + ""; // config required
const searchTexts = configs.get( "conf_SearchTexts" ) + ""; // config required
const dataIdC     = configs.get( "conf_DataIdC" ) + "";     // config required

if( targetColId === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Column ID} is empty \n" );
}
if( searchTexts === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Search Texts} is empty \n" );
}
const numTargetColId = parseInt( targetColId );


//// == Data Retrieving / ワークフローデータの参照 ==
const inputString = engine.findDataByNumber( dataIdA ) + "";
const arrInputString = inputString.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " TSV {A}, number of lines: " + arrInputString.length );


//// == Calculating / 演算 ==
let   outputString = "";
const arrSearchTexts = searchTexts.split(",");
let   arrSearchRegExp = [];
for( let i = 0; i < arrSearchTexts.length; i++ ){
  engine.log( " AutomatedTask Search Text[" + i +"]: " + arrSearchTexts[i] );
  if( arrSearchTexts[i] === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {Search Text[" + i +"]} is empty \n" );
  }
  let contain = new RegExp( arrSearchTexts[i]
                            .replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&')
                          ); // Escaping for a literal string search
  // For a wider range of values, comment out and use Patterns with special characters
  arrSearchRegExp.push( contain );
}
for( let i = 0; i < arrInputString.length; i++ ){
  let arrTsvLine = arrInputString[i].split("\t");
  for( let j = 0; j < arrSearchRegExp.length; j++ ){
    if( arrSearchRegExp[j].test( arrTsvLine[ numTargetColId ] ) ){
      outputString += arrInputString[i];
      outputString += "\n";
      break;
    }
  }
}
outputString = outputString.replace(/[\n]*$/, "");


//// == Data Updating / ワークフローデータへの代入 ==
if( outputString === "" ){
  engine.log( " AutomatedTask DataUpdating: Output Text empty" );
}
engine.setDataByNumber( dataIdC, outputString );

} //////// END "main()" /////////////////////////////////////////////////////////////////

Download

2021-07-09 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/tsv-string-filter-by-text-2021/
The Add-on import feature is available with Professional or Enterprise edition.

Notes

  1. Cannot specify search terms that contain a comma.
  2. For “AND search”, try to place this Automated Step serially.
  3. Special characters in search text settings have no meaning (literal string).

Capture

See also

3 thoughts on “TSV String, Filter by Text”

  1. Pingback: TSV String, Filter Out by Text – Questetra Support

  2. Pingback: TSV String, Filter by Date – Questetra Support

  3. Pingback: TSV String, Filter by Datetime – Questetra Support

Comments are closed.

%d bloggers like this: