Jump to content

split txt file into more textfiles


  • Please log in to reply
8 replies to this topic

#1
mtwo

mtwo

    InsanelyMac Protégé

  • Members
  • Pip
  • 12 posts
  • Gender:Male
  • Location:stockholm
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 :(

#2
A Nonny Moose

A Nonny Moose

    Proud PPC User

  • Members
  • PipPipPipPipPipPipPipPipPipPip
  • 2,421 posts
  • Gender:Male
I'd try Automator, but that would force some highlighting and clicking.

#3
thePixeler

thePixeler

    InsanelyMac Protégé

  • Members
  • Pip
  • 25 posts
  • Gender:Male
  • Location:Rhode Island, USA
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.

Attached Files



#4
mtwo

mtwo

    InsanelyMac Protégé

  • Members
  • Pip
  • 12 posts
  • Gender:Male
  • Location:stockholm
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 Im not so good in apple script so i could be that its 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


#5
thePixeler

thePixeler

    InsanelyMac Protégé

  • Members
  • Pip
  • 25 posts
  • Gender:Male
  • Location:Rhode Island, USA
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...
property pathToDesktop : "Macintosh HD:Users:yourusername:Desktop:"
To...
property pathToDesktop : "Macintosh HD:Users:Steve Jobs:Desktop:"

Attached Files



#6
pafmax

pafmax

    InsanelyMac Protégé

  • Just Joined
  • Pip
  • 1 posts
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 youd 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? Its just a nitpick, I know....

Thanks for the script, Ill be sure to mention you! (youve just saved me a lot of work!)



Edit: Ok, nevermind, I can actually use this "bug" in my favour! ;)

#7
thePixeler

thePixeler

    InsanelyMac Protégé

  • Members
  • Pip
  • 25 posts
  • Gender:Male
  • Location:Rhode Island, USA

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 youd 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? Its just a nitpick, I know....

Thanks for the script, Ill be sure to mention you! (youve 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.

#8
iMichael

iMichael

    InsanelyMac Protégé

  • Just Joined
  • Pip
  • 2 posts
  • Gender:Male
  • Location:Warsaw, Poland
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?

#9
thePixeler

thePixeler

    InsanelyMac Protégé

  • Members
  • Pip
  • 25 posts
  • Gender:Male
  • Location:Rhode Island, USA

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.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy