Divide the file in multiple parts

hello guys,

I have a file which has around 1900 computer names . I am using computer removal tool to delete them.
As i don’t want to remove all 1900 at once , and want to divide it in 4 parts where each file carries 500 items.

How would i achieve this ?

Any suggestions!!!

This isn’t so much a BigFix question. You would do it the same way you would break up any file for any purpose.

Are you asking how you would do this with relevance and actionscript?

Yes… i want to do it via action script .

If you are going to do it entirely with actionscript and relevance substitution, then you will probably need to know exactly how many lines are in the file beforehand if you want exactly 500 items per batch.

If you wanted to break it up into 4 evenly divided batches no matter how many items total were in the file, then that would be much more easily done.

Otherwise if you really must have 500 items per batch with an unknown number of total items / batches, then you will need to use actionscript to run some other code to actually accomplish this.


lines:

lines of file "C:\Windows\Temp\_computer_names.txt"

First 500 lines:

lines whose(500 >= line number of it) of file "C:\Windows\Temp\_computer_names.txt"

Thanks jgstew

The dividing of file in equal parts would also work… but how would i right this out.

First of all, your file with a bunch of computer names, how is it laid out?

Is it one computer name per line?

Is it a bunch of computer names on a single line, separated by something?

You can use relevance to count the exact number of computer names in the file, then divide that number by 4, then break it up into 4 parts.

I think that’s easier said than done…I had to fight with this for quite a bit, before coming up with the very ugly expression. I feel that there is probably some much simpler way that I’m overlooking. The “4” in “of (4, it) of file ‘c:\temp\test2.txt’” can be modified to split the file into any number of partitions.

(item 0 of it, item 3 of it) of (integers in (0, item 0 of it - 1 ), item 0 of it, number of lines of item 1 of it, lines of item 1 of it) whose ((line number of item 3 of it - 1) >= (item 2 of it / item 1 of it) * item 0 of it AND (line number of item 3 of it - 1) < item 2 of it / item 1 of it * (item 0 of it + 1))  of (4, it) of file "c:\temp\test2.txt"

For a 1000-line host file, this gives results of the form

A: 0, host1
A: 0, host2
A: 0, host3
A: 0, host4
...
A: 0, Host249 
A: 0, Host250 
A: 1, Host251 
A: 1, Host252 
A: 1, Host253 
...
A: 1, Host499 
A: 1, Host500 
A: 2, Host501 
A: 2, Host502 
A: 2, Host503 
...
A: 2, Host748 
A: 2, Host749 
A: 2, Host750 
A: 3, Host751 
A: 3, Host752 

In this result, item 0 gives “which partition in which to place the line” and item 1 gives “the line to place the partition”. I was pleasantly surprised that this evaluated my 1000-line file in only 20 ms, I expected quite a bit more given that the file must be read at least four times.

I haven’t put it into an Action to test yet, but I think the following actionscript should (on Windows) create files “output0.txt”, “output1.txt”, “output2.txt”, and “output3.txt”, with each file containing one fourth of the source file:

delete __appendfile
appendfile {concatenation "%0d%0a" of ("echo " & item 1 of it & " >> output" & item 0 of it as string & ".txt") of  (item 0 of it, item 3 of it) of (integers in (0, item 0 of it - 1 ), item 0 of it, number of lines of item 1 of it, lines of item 1 of it) whose ((line number of item 3 of it - 1) >= (item 2 of it / item 1 of it) * item 0 of it AND (line number of item 3 of it - 1) < item 2 of it / item 1 of it * (item 0 of it + 1))  of (4, it) of file "c:\temp\test2.txt"}
delete BuildOutput.cmd
move __appendfile BuildOutput.cmd
delete output0.txt
delete output1.txt
delete output2.txt
delete output3.txt
waithidden BuildOutput.cmd
2 Likes

This is much more elegant than what I was thinking of doing. Nice work.

May I ask what the use case is for this? The computer remover can easily handle deleting 1000s of computers in a single run, so there is no need to split the file for load distribution.

1 Like

Honestly I was mostly intrigued by the challenge. I agree the computer remover tool can handle thousands; nevermind that it removes them sequentially, so in terms of resource use I don’t see a difference between deleting 5 and 5,000.

Of course, if you aren’t completely confident that you’re removing the correct computers, recovering from deleting 5 is much better than 5,000. I approached the tool with some trepidation the first time.

2 Likes

Thanks Jason,

It is great . You have helped me out in this .