Help - Search - Members - Calendar
Full Version: split txt file into more textfiles
InsanelyMac Forum > Apple World > Mac Programming and Development > AppleScript and Automator
mtwo
i got a textfile that is like this:

a girl@a boy@a dog@.... and so on

I want to in some way split this file at those "@" so they become small files that are named like this 01.txt 02.tx ..

i tried csplit but i couldnt get it to work
any type of help would be appreciated smile.gif
A Nonny Moose
I'd try Automator, but that would force some highlighting and clicking.
thePixeler
See if this script works. You can drop text files on it or double click the app and choose one. Right now it only works with ".txt" files.
mtwo
Thank you very much Pixeler but I got a strange problem :S It says the variable theFolder is not defined .. But when i look into the surce it seems that it is defined .. But I´m not so good in apple script so i could be that it´s defined in the wrong way.
CODE
tell application "Finder"
                set theNumber to ""
                repeat 5 times
                    try
                        make new folder at ((path to desktop) as string) with properties {name:"Text fragments " & theNumber}
                        set theFolder to (((path to desktop) as string) & "Text fragments " & theNumber & ":") as string
                        exit repeat
                    on error theError
                        if theError is "The operation could not be completed because there is already an item with that name." then
                            set theNumber to theNumber + 1
                        end if
                    end try
                end repeat
            end tell
thePixeler
OK try this one! You'll have to edit it first though, open it up and change the first line to the path to your desktop.

So change...
CODE
property pathToDesktop : "Macintosh HD:Users:yourusername:Desktop:"

To...
CODE
property pathToDesktop : "Macintosh HD:Users:Steve Jobs:Desktop:"
pafmax
thePixeler.... I just have to say blink.gif

I was looking for this exact type of script today to process one of my work txt files (about 80M of txt with 2000 merged files inside)

The one tiny litle ploblem is that, when it finds the character or piece of text you´d like to cut, it cleans that character.

In my adapted program, if I ask the program to cut everything after "position" the resulting txt file will start with "osition".

Can this be solved? It´s just a nitpick, I know....

Thanks for the script, I´ll be sure to mention you! (you´ve just saved me a lot of work!)



Edit: Ok, nevermind, I can actually use this "bug" in my favour! smile.gif
thePixeler
QUOTE(pafmax @ Dec 10 2007, 07:48 PM) *
thePixeler.... I just have to say blink.gif

I was looking for this exact type of script today to process one of my work txt files (about 80M of txt with 2000 merged files inside)

The one tiny litle ploblem is that, when it finds the character or piece of text you´d like to cut, it cleans that character.

In my adapted program, if I ask the program to cut everything after "position" the resulting txt file will start with "osition".

Can this be solved? It´s just a nitpick, I know....

Thanks for the script, I´ll be sure to mention you! (you´ve just saved me a lot of work!)
Edit: Ok, nevermind, I can actually use this "bug" in my favour! smile.gif

It's not really a bug, it would take one simple line of code to make it include the cut character. I thought this would be annoying so i didn't make it do this.

But you say the current version works for you so I'll keep it the way it is, for now.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.