Separation help

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Separation help

Post by timle » Mon May 14, 2012 10:03 pm

Hello,
I have this string of text:
-rw-r--r-- 1 1000 1001 1287419 May 14 16:12 A02_05_14_2012_1FIRST_1_K0_HN.pdf
-rw-r--r-- 1 1000 1001 979252 May 14 15:15 A03_05_14_2012_1FIRST_1_K0_HN.pdf

I want to separate to get the file size, but when I separate them, they dont give me the consistent position

Readfile>c:\dirfile.txt,data
separate>data,CRLF,data
separate>data_1, ,size1

I try to capture the file size, but the large file is listed under SIZE1_17 and the smaller file size is listed under SIZE1_18, how can I get them in the same place all the time

thank you

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon May 14, 2012 10:10 pm

A couple of thoughts.

Are you getting this data from unix? Perhaps your problem is in the first separate, Unix doesn't give you a CRLF at the end of a line, just a CR.

Is the separator between elements in each line a space or a tab?

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Post by timle » Mon May 14, 2012 10:46 pm

Actually I am getting the list from FTPGetDirList and CRLF works fine, it just individual line giving me problem.
I am trying to get the "979252" and "3777934" since they are not the same length, with space in the front it create some difficulty.

there are spaces between element in the line, not tab

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon May 14, 2012 11:36 pm

OK I think I see the issue. Varying numbers of spaces. This works with the fake data I created. Does it work with your real data? Basically running through the separated items and renumbering them based on whether or not they contain text.

Code: Select all

LabelToVar>Data,data

Separate>data,crlf,Line

Let>kk=0
Repeat>kk
  Add>kk,1
  Let>value=Line_%kk%
  Separate>value,space,item
  Let>ii=0
  Let>gg=0
  Repeat>ii
    Add>ii,1
    Let>value=item_%ii%
    If>value=
    Else
      Add>gg,1
      Let>Test_%gg%=value
    EndIf
  Until>ii=item_count
  Let>Line_%kk%_size=Test_5
Until>kk={%Line_Count%-1}


**BREAKPOINT**

/*
Data:
-rw-r--r-- 1 1000 1001 1287419 May 14 16:12 A02_05_14_2012_1FIRST_1_K0_HN.pdf
-rw-r--r-- 1 1000 1001  979252 May 14 15:15 A03_05_14_2012_1FIRST_1_K0_HN.pdf
-rw-r--r-- 1 1000 1001     419 May 14 16:12 A02_05_14_2012_1FIRST_1_K0_HN.pdf
-rw-r--r-- 1 1000 1001    9252 May 14 15:15 A03_05_14_2012_1FIRST_1_K0_HN.pdf
-rw-r--r-- 1 1000 1001      19 May 14 16:12 A02_05_14_2012_1FIRST_1_K0_HN.pdf
-rw-r--r-- 1 1000 1001   39252 May 14 15:15 A03_05_14_2012_1FIRST_1_K0_HN.pdf
*/

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Post by timle » Tue May 15, 2012 12:04 am

JRL
It didn't work for me for some reason! I got the same result

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue May 15, 2012 4:14 am

If the problem really is multiple spaces then try:

Code: Select all

Readfile>c:\dirfile.txt,data 
Separate>data,crlf,Line
Let>kk=0
Repeat>kk
Add>kk,1
Let>value=Line_%kk%
Separate>value,space,item
Let>ff=%item_count%-9
If>ff>0
Let>qq=0
Repeat>qq
Add>qq,1
StringReplace>value,  , ,value
Until>qq=ff
EndIf
Separate>value,space,item
MDL>item_5
Until>kk={%Line_Count%}

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Post by timle » Tue May 15, 2012 5:40 pm

Thank you this works!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue May 15, 2012 10:48 pm

JRL's posted code works for me, not sure why it doesn't work for you.

There is probably a regex solution too.

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Post by timle » Tue May 15, 2012 11:47 pm

Me_again wrote:JRL's posted code works for me, not sure why it doesn't work for you.

There is probably a regex solution too.
May be the string replace is needed. to make it work. thank you you both

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed May 16, 2012 11:49 pm

Me_again wrote:There is probably a regex solution too.
There sure is... and its shorter and simpler too!

Code: Select all

Let>line=-rw-r--r-- 1 1000 1001 1287419 May 14 16:12 A02_05_14_2012_1FIRST_1_K0_HN.pdf
Let>pattern=[^0-9]+(\d+) +(\d+) +(\d+) +(\d+).*
RegEx>pattern,line,0,matches,num,1,$4,file_size
MDL>file_size

Let>line=-rw-r--r-- 1 1000 1001 979252 May 14 15:15 A03_05_14_2012_1FIRST_1_K0_HN.pdf
Let>pattern=[^0-9]+(\d+) +(\d+) +(\d+) +(\d+).*
RegEx>pattern,line,0,matches,num,1,$4,file_size
MDL>file_size
By the way, this regex will work as long as the input lines always:

- start with one or more non-digits
- followed by one or more contiguous digits
- followed by one or more contiguous spaces
- followed by one or more contiguous digits
- followed by one or more contiguous spaces
- followed by one or more contiguous digits
- followed by one or more contiguous spaces
- followed by one or more contiguous digits - which is the file size

Enjoy!
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Post by timle » Wed May 16, 2012 11:51 pm

cool, I will give it a try

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu May 17, 2012 8:22 am

You could also use a MidStr command based on the longer positions and LTrim the result

Code: Select all

Let>string1=-rw-r--r-- 1 1000 1001 1287419 May 14 16:12 A02_05_14_2012_1FIRST_1_K0_HN.pdf
Let>string2=-rw-r--r-- 1 1000 1001  979252 May 14 15:15 A03_05_14_2012_1FIRST_1_K0_HN.pdf
Let>string3=-rw-r--r-- 1 1000 1001     419 May 14 16:12 A02_05_14_2012_1FIRST_1_K0_HN.pdf
Let>string4=-rw-r--r-- 1 1000 1001      19 May 14 16:12 A02_05_14_2012_1FIRST_1_K0_HN.pdf

MidStr>%string1%,24,7,len1
MidStr>%string2%,24,7,len2
MidStr>%string3%,24,7,len3
MidStr>%string4%,24,7,len4

LTrim>%len1%,len1
LTrim>%len2%,len2
LTrim>%len3%,len3
LTrim>%len4%,len4

MessageModal>1=%len1%%CRLF%2=%len2%%CRLF%3=%len3%%CRLF%4=%len4%

Last edited by Bob Hansen on Fri May 18, 2012 2:05 am, edited 2 times in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Post by timle » Thu May 17, 2012 3:20 pm

You guys are first-rate support!!

Thank you

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu May 17, 2012 6:23 pm

jpuziano wrote:
Me_again wrote:There is probably a regex solution too.
There sure is... and its shorter and simpler too!
Well, this is shorter and simpler :wink:

Code: Select all

Let>pattern=[ ]{1,}
Readfile>c:\dirfile.txt,data
Separate>data,crlf,Line
Let>kk=0
Repeat>kk
Add>kk,1
Let>value=Line_%kk%
RegEx>pattern,value,0,matches,num,1, ,value
Separate>value, ,item
MDL>item_5
Until>kk={%Line_Count%}

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu May 17, 2012 8:36 pm

Me_again wrote:Well, this is shorter and simpler :wink:

Code: Select all

Let>pattern=[ ]{1,}
Readfile>c:\dirfile.txt,data
Separate>data,crlf,Line
Let>kk=0
Repeat>kk
Add>kk,1
Let>value=Line_%kk%
RegEx>pattern,value,0,matches,num,1, ,value
Separate>value, ,item
MDL>item_5
Until>kk={%Line_Count%}
Clever concept Me_again, thanks for sharing.

However by using the regex I posted, we can reduce it from 11 down to 9 lines... see below:

Code: Select all

Let>pattern=[^0-9]+(\d+) +(\d+) +(\d+) +(\d+).*
Readfile>c:\dirfile.txt,data
Separate>data,crlf,Line
Let>kk=0
Repeat>kk
Add>kk,1
RegEx>pattern,Line_%kk%,0,matches,num,1,$4,file_size
MDL>file_size
Until>kk={%Line_Count%}
Can anyone accomplish the above in less than 9 lines?
Last edited by jpuziano on Fri May 18, 2012 4:42 pm, edited 1 time in total.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts