Jump to content

split txt file into more textfiles


mtwo
 Share

9 posts in this topic

Recommended Posts

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 :(

Link to comment
Share on other sites

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.

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

Link to comment
Share on other sites

thePixeler.... I just have to say :(

 

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! ;)

Link to comment
Share on other sites

thePixeler.... I just have to say ;)

 

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! :)

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.

Link to comment
Share on other sites

  • 2 years later...

I've tried to make this work with Unicode files, with no luck ("open" and "write" as «class utf8»). Keeps saying "Can't make alias -path to file- into type file specification"

Anyone knows how to fix this?

Link to comment
Share on other sites

I've tried to make this work with Unicode files, with no luck ("open" and "write" as �class utf8�). Keeps saying "Can't make alias -path to file- into type file specification"

Anyone knows how to fix this?

Blast from the past!

I don't think I can help you, man. Just yesterday I sold my Mac. All I have now is a Windows box.

From my previous posts it appears that the script will only works on ".txt" files. If you're using unicode that probable means that you have ".rtf"

files. I really doubt that this will work but try changing all references of ".txt" to ".rtf" in the script. I vaguely remember doing something with unicode before and you had to do something with theses funky arrows or something...

You might also want to try modifying the script to use TextEdit as a means of opening and saving your files.

Link to comment
Share on other sites

 Share

×
×
  • Create New...