[futurebasic] UNIX split command

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2006 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Sun, 26 Nov 2006 18:43:42 -0500
As soon as I hit the "Send" button in my last post, I realized that I 
was remiss in explaining where the Unix split command places its 
files.

In Bernie's original example:


	 split -l 1000 /MyFile


there is no output file specified. In this case split will break the 
original document into as many separate 1000-line files as it takes 
and save them to the root level of the user's account using this 
convention:

xaa
xab
xac
xad
...

This means you may have to go hunting for them. On the other hand, 
you can specify an output directory and file name when invoking split:


	 split -l 1000 /MyFile ~/Desktop/MySplitFiles/mySplitFile


In this example, split will create a new folder "MySplitFiles" on 
your Desktop. The split 1000-line files in it will be named like this:

mySplitFileaa
mySplitFileab
mySplitFileac
mySplitFilead
...

Apologies for not clarifying this in the original post.

Ken



>Bernie asked,
>
>>I want to use the split command to break a FB file into separate 1000
>>line files:
>>
>>	split -l 1000 /MyFile
>>
>>Unfortunately, it looks like it only counts lines that end with LF.
>>Is there any way to tell UNIX that lines end with CR?
>
>
>Bernie,
>
>Sure.
>
>Short explanation:
>
>
>        tr "\r" "\n" < /MyFile >; split -l 1000 /MyFile
>
>
>Long explanation:
>
>Just run the original file through the Unix translator (man tr for 
>options) and replace the CRs ( "\r" in Unix ) with LFs ( "\n" ) -- 
>takes a split second even on huge files -- and then do your split.
>
>If you want to translate your existing file in place changing CRs to 
>LFs, use this:
>
>        tr "\r" "\n" < ~/Desktop/OldCRfile.txt >
>
>
>I prefer not to touch the original file, but rather to create a new 
>one like this:
>
>        tr "\r" "\n" < ~/Desktop/OldCRfile.txt > ~/Desktop/NewLFFile.txt
>
>
>Then do your split on the new file:
>
>        split -l 1000 ~/Desktop/NewLFFile.txt
>
>
>You can now optionally reverse wash the split file through tr to 
>restore your CRs if you so desire:
>
>
>        tr "\n" "\r" < ~/Desktop/NewLFFile.txt > ~/Desktop/NewCRFile.txt
>
>
>It takes longer to read this than to translate and split 1000 files.
>
>
>Ken