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.

  • March 21, 2023
  • 3 replies
  • 16 views

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"

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

hkingsbury
Celebrity
Forum|alt.badge.img+63
  • Celebrity
  • 1620 replies
  • 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
  • 12 replies
  • 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"

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+58
  • Evangelist
  • 932 replies
  • 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