terça-feira, 26 de agosto de 2014

Unix - how you can split a file to n-files?

You could use split command in unix:

split -l[max line number per file] file [prefix]

The default will create PREFIXaa, PREFIXab, ..

If you whan to exchange the lengh of suffixes, use -a [numer]. Will create PREFIXaaaa, PREFIXaaab,... If -a 4.
 

Example to split readme.txt that have 1000 lines into 10 files with name new_000 at new_009

split -l 100 -d 2 readme.txt new_


The man page:

       Output  fixed-size  pieces of INPUT to PREFIXaa, PREFIXab, ...; default
       size is 1000 lines, and default PREFIX is 'x'.  With no INPUT, or  when
       INPUT is -, read standard input.

       Mandatory  arguments  to	 long  options are mandatory for short options
       too. 
 -a, --suffix-length=N
	      use suffixes of length N (default 2) 
 -b, --bytes=SIZE
	      put SIZE bytes per output file 
 -C, --line-bytes=SIZE
	      put at most SIZE bytes of lines per output file 
 -d, --numeric-suffixes
	      use numeric suffixes instead of alphabetic 
-l, --lines=NUMBER
	      put NUMBER lines per output file 
 --verbose
	      print a diagnostic to standard error  just  before  each	output
	      file is opened 
 --help display this help and exit 
 --version
	      output version information and exit 
SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg. 

Nenhum comentário:

Postar um comentário