Solved

Is there a better way to do basic math? I'm trying to parse file names from an SFTP call.


Badge +1

I'm parsing data from an SFTP call to get the file name. I'm returning _list values that have all the FTP properties of each file. I use an AttributeCreator get the length of this string as an attribute (ListStringLength=69) --- @StringLength(@Value(_list))

  • -rwxrwxrwx  1 user   278361 date 00137 0001539147T ABCDEFG1234567.jpg

 

I'm also using the AttributeCreator to get the starting position of the file name based on the prefix as another attribute (StartingPosition=33) --- @FindString(@Value(_list),"00137 0001539147T")

  • 278361 Mar 21 09:49 00137 0001539147T ABCDEFG1234567.jpg

 

From here, I tried to simply subtract. But that didn't work.

@Value(ListStringLength)-@Value(StartingPosition) = a string value 69-33

 

So then I added an SQLExecuter and did the math in SQL and output the FileNameLength.

select @Value(ListStringLength)-@Value(StartingPosition) as FileNameLength

 

From here, I added an AttributeCreator to get the FileName. @Substring(@Value(_list),@Value(StartingPosition),@Value(FileNameLength))

 

I've uploaded my test fmw.

 

Thanks,

James

 

 

 

 

icon

Best answer by hkingsbury 21 March 2023, 19:53

View original

3 replies

Userlevel 5
Badge +29

To perform arithmetic you need to wrap your statement (or part of a statement) in @Evaluate().

Take:

  • a=8
  • b=3
  • c=test

 

@Value(a)+@Value(b) = "8+3"

@Evaluate(@Value(a)+@Value(b)) = 11

@Value(c)-@Value(a) = "test-3"

@Evaluate(@Value(c)-@Value(a)) = <error>, can't subtract a number from a non number

@Value(c)+@Evaluate(@Value(a)*@Value(b))="test+24"

Badge +1

To perform arithmetic you need to wrap your statement (or part of a statement) in @Evaluate().

Take:

  • a=8
  • b=3
  • c=test

 

@Value(a)+@Value(b) = "8+3"

@Evaluate(@Value(a)+@Value(b)) = 11

@Value(c)-@Value(a) = "test-3"

@Evaluate(@Value(c)-@Value(a)) = <error>, can't subtract a number from a non number

@Value(c)+@Evaluate(@Value(a)*@Value(b))="test+24"

Ah! Brilliant! Thank you @hkingsbury​. I played around with @Evaluate but didn't have the syntax correct. This works great and eliminates the need for the SQLExecutor.

Userlevel 4
Badge +36

If you don't want to do the math, you can leverage the power of regular expressions.

Both expressions below give the same results (I added an attribute with the file prefix).

@ReplaceRegEx(@Value(_list),^.*@Value(Prefix),@Value(Prefix))
@ReplaceRegEx(@Value(_list),.*?(@Value(Prefix)),\1)

Regex_Filename_Prefix 

Reply