[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:08:29 -0500
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