Skip to main content
Solved

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


fmejamesl
Contributor
Forum|alt.badge.img+5

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

 

 

 

 

Best answer by hkingsbury

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"

View original
Did this help you find an answer to your question?

3 replies

hkingsbury
Celebrity
Forum|alt.badge.img+54
  • Celebrity
  • Best Answer
  • March 21, 2023

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"


fmejamesl
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • March 21, 2023
hkingsbury wrote:

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.


geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • March 23, 2023

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 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings