LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Splitting file (https://www.linuxquestions.org/questions/linux-newbie-8/splitting-file-4175501924/)

azheruddin 04-16-2014 05:32 AM

Splitting file
 
Hello
I have one file which is around 20MB.
File name = ABCD_XYZ_20130302223203.xml

wanted to split up into four files of each size of 5 MB.


Requirement is that to write script which should do as : first three file should be of size 5 MB each, the fourth one content should be in the last file whatever it may be less or more than 5 MB.

*Splitted file name should be same as the original with appeneding 1,2,3.


I have used
split -b 5M ABCD_XYZ_20130302223203.xml
but its splitting in file name as
xaa
xab
xac
xad


Appreciate your help in this.

pan64 04-16-2014 05:48 AM

so read the man page of split:
Code:

split [OPTION]... [INPUT [PREFIX]]

Output  fixed-size  pieces  of  INPUT to PREFIXaa, PREFIXab, ...;

 -b, --bytes=SIZE
              put SIZE bytes per output file

  -d, --numeric-suffixes
              use numeric suffixes instead of alphabetic

I think you only need to find PREFIX and suffix properly

azheruddin 04-16-2014 07:15 AM

Thanks for your advice

My Box is AIX and I dont a have -d option for numeric suffix.

I am using

filename="ABCD_XYZ_20130302223203.xml"
split -b 5M -a2 $filename "${filename}_"

got some output like
ABCD_XYZ_20130302223203.xml_aa
ABCD_XYZ_20130302223203.xml_ab

But the expected one as...
ABCD_XYZ_20130302223203_1.xml
ABCD_XYZ_20130302223203_2.xml

OR
Same name for all splitted files as original like
ABCD_XYZ_20130302223203.xml
ABCD_XYZ_20130302223203.xml
ABCD_XYZ_20130302223203.xml
ABCD_XYZ_20130302223203.xml


Appreciate your input.

schneidz 04-16-2014 07:58 AM

[aix sux]
this could be messy but:
Code:

i=0;for file in x*
do
 i=`expr $i + 1`
 mv $file ABCD_XYZ_20130302223203_$i.xml
done



All times are GMT -5. The time now is 04:03 AM.