LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-16-2014, 06:32 AM   #1
azheruddin
Member
 
Registered: Dec 2011
Posts: 77
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
Old 04-16-2014, 06:48 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
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
 
Old 04-16-2014, 08:15 AM   #3
azheruddin
Member
 
Registered: Dec 2011
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-16-2014, 08:58 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
[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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
File splitting script stephencassidy Programming 3 03-23-2007 01:09 PM
splitting a tar file s_hcl Linux - General 3 09-07-2006 02:45 PM
Online File Splitting Randvegeta Linux - Networking 7 04-29-2005 02:25 PM
Splitting a File Slayer097 Linux - Newbie 4 02-22-2005 08:15 PM
file splitting???? spideywebsling Linux - General 4 07-19-2004 07:42 PM


All times are GMT -5. The time now is 10:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration