Splitting large files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Splitting large files
# 1  
Old 12-07-2005
Question Splitting large files

Hi Unix gurus,

We have a masterfile which is to be split into smallerfiles with names as
masterfile00,masterfile01,masterfile03...etal
I was able to split the file using the "Split" cmd
but as masterfileaa,masterfileab..
Is it posiible to change the default suffix?
or is there any other cmd which does the needful
or do we need to rename the smallerfiles

thanking you in anticipation
Rvbs
# 2  
Old 12-07-2005
using a shell script...

hi Rvbs,

i dont think so if its possible to change the format of "split" command as per your requiremnet, so i guess you have to write a shell script to modify the ouput of "split" command.

i have written a sample shell script which will split the files into your desired format (suffix as numerals).

please test the same Smilie ....n tell me if it works fine Smilie ...

note:
1. you have to pass the name of file to split and the number of lines for splitting the input files, as the command line argumnets ($1 and $2 in the same order as above)
2. run the script from same directory/shell where your input file is existing or else give the proper path Smilie
3. you can modify the split command used here for any different options/flags...as per your requirement.

script:

set -x
#/usr/bin/sh
export name_of_file_to_split=$1
export num_of_lines=$2
export PWD=`pwd`
export len_of_input_file_name=`echo $name_of_file_to_split | wc -c`
export len_of_input_file_name=`expr $len_of_input_file_name - 1`
split -l "$num_of_lines" $name_of_file_to_split $name_of_file_to_split
ls $name_of_file_to_split* > temp_file
export input_file=$PWD/temp_file
number_of_sub_files=`cat $input_file | wc -l`
i=2
while [ $i -le $number_of_sub_files ]
do
old_file_name=`cat $input_file | head -"$i" | tail -1`
len=`echo $old_file_name | wc -c`
len=`expr $len - 1`
len_to_cut=`expr $len_of_input_file_name + 1`
old_suffix=`echo $old_file_name | cut -c "$len_to_cut"-"$len"`
new_suffix=`echo $old_suffix | tr a-z 0-9`
mv $old_file_name "$name_of_file_to_split""$new_suffix"
i=`expr $i + 1`
done
rm -f temp_file


regards,
Bhups
# 3  
Old 12-07-2005
csplit should do the job, try 'man csplit'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a large file as per date

Hi, I need a suggestion for an issue in UNIX file. I have a log file in my system where data is appending everyday and as a consequence the file is increasing heavily everyday. Now I need a logic to split this file daily basis and remove the files more than 15 days. Request you to... (3 Replies)
Discussion started by: bhaski2012
3 Replies

2. Shell Programming and Scripting

Sed: Splitting A large File into smaller files based on recursive Regular Expression match

I will simplify the explaination a bit, I need to parse through a 87m file - I have a single text file in the form of : <NAME>house........ SOMETEXT SOMETEXT SOMETEXT . . . . </script> MORETEXT MORETEXT . . . (6 Replies)
Discussion started by: sumguy
6 Replies

3. Shell Programming and Scripting

Splitting large file and renaming based on field

I am trying to update an older program on a small cluster. It uses individual files to send jobs to each node. However the newer database comes as one large file, containing over 10,000 records. I therefore need to split this file. It looks like this: HMMER3/b NAME 1-cysPrx_C ACC ... (2 Replies)
Discussion started by: fozrun
2 Replies

4. Shell Programming and Scripting

Splitting large file into multiple files in unix based on pattern

I need to write a shell script for below scenario My input file has data in format: qwerty0101TWE 12345 01022005 01022005 datainala alanfernanded 26 qwerty0101mXZ 12349 01022005 06022008 datainalb johngalilo 28 qwerty0101TWE 12342 01022005 07022009 datainalc hitalbert 43 qwerty0101CFG 12345... (19 Replies)
Discussion started by: jimmy12
19 Replies

5. Shell Programming and Scripting

splitting a large text file into paragraphs

Hello all, newbie here. I've searched the forum and found many "how to split a text file" topics but none that are what I'm looking for. I have a large text file (~15 MB) in size. It contains a variable number of "paragraphs" (for lack of a better word) that are each of variable length. A... (3 Replies)
Discussion started by: lupin..the..3rd
3 Replies

6. Shell Programming and Scripting

Splitting a large file, split command will not do.

Hello Everyone, I have a large file that needs to be split into many seperate files, however the text in between the blank lines need to be intact. The file looks like SomeText SomeText SomeText SomeOtherText SomeOtherText .... Since the number of lines of text are different for... (3 Replies)
Discussion started by: jwillis0720
3 Replies

7. Shell Programming and Scripting

Help with splitting a large text file into smaller ones

Hi Everyone, I am using a centos 5.2 server as an sflow log collector on my network. Currently I am using inmons free sflowtool to collect the packets sent by my switches. I have a bash script running on an infinate loop to stop and start the log collection at set intervals - currently one... (2 Replies)
Discussion started by: lord_butler
2 Replies

8. UNIX for Dummies Questions & Answers

splitting the large file into smaller files

hi all im new to this forum..excuse me if anythng wrong. I have a file containing 600 MB data in that. when i do parse the data in perl program im getting out of memory error. so iam planning to split the file into smaller files and process one by one. can any one tell me what is the code... (1 Reply)
Discussion started by: vsnreddy
1 Replies

9. Shell Programming and Scripting

Splitting large file into small files

Hi, I need to split a large file into small files based on a string. At different palces in the large I have the string ^Job. I need to split the file into different files starting from ^Job to the last character before the next ^Job. Also all the small files should be automatically named.... (4 Replies)
Discussion started by: dncs
4 Replies

10. UNIX for Dummies Questions & Answers

Splitting a large log file

Okay, absolute newbie here... I'm on a Mac trying to split an almost 2 Gig log file on a Unix box into manageable chunks for my web-based log analysis tool. What do I need to do, what programs do I need to do it? All and any help appreciated/needed :-) Cheers (8 Replies)
Discussion started by: simmonet
8 Replies
Login or Register to Ask a Question