Operating System - HP-UX
1751968 Members
4539 Online
108783 Solutions
New Discussion юеВ

Re: split files with formatted output name

 
Anand_30
Regular Advisor

split files with formatted output name

Hi,

I have to split a big file into a number of smaller files. I know that split command will do the trick for me but my requirement is that the output files should be suffixed with 0,1,2,3...(example out1, out2, out3...) and not aa,ab like what split does.

Can anyone please help me.

Thanks,
Andy
3 REPLIES 3
Rodney Hills
Honored Contributor

Re: split files with formatted output name

Here's a one line perl script. It will break up the files into 100 lines each.

cat bigfile | perl -pe 'open(STDOUT,">out".++$cnt) unless ($.-1) % 100;'

HTH

-- Rod Hills
There be dragons...
Jeff_Traigle
Honored Contributor

Re: split files with formatted output name

Or see if csplit(1) will work for you... it appends numbers instead of letters according to the man page.
--
Jeff Traigle
Jeff Schussele
Honored Contributor

Re: split files with formatted output name

Hi Andy,

You might try the csplit command & use -f prefix. For example:

-f out

will result in out00 out01 out02 etc.

man csplit for further details.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!