Split files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split files
# 1  
Old 06-30-2014
Data Split files

Hi ,

I have 100 records in a.txt file

Need to split the a.txt file in to 5 files

1ST File:

ex: My file name should be a1.txt - line count in file should be 1 to 15

2ND File:

ex: My file name should be a2.txt - line count in file should be 16 to 40

3ND File:

ex: My file name should be a3.txt - line count in file should be 41 to 60

4th file:

ex: My file name should be a4.txt - line count in file should be 61 to 90

5th file:

ex: My file name should be a4.txt - line count in file should be 91 to 10
# 2  
Old 06-30-2014
Did you try anything at all?

This might work:
Code:
awk     'NR==1          {n=split(LNS,LN,",")}
         NR>LN[CNT]     {CNT++; FN="a"CNT".txt"}
                        {print $0 >FN}
        ' LNS="15,40,60,90,100" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. UNIX for Beginners Questions & Answers

Split and Rename Split Files

Hello, I need to split a file by number of records and rename each split file with actual filename pre-pended with 3 digit split number. What I have tried is the below command with 2 digit numeric value split -l 3 -d abc.txt F (# Will Produce split Files as F00 F01 F02) How to produce... (19 Replies)
Discussion started by: techedipro
19 Replies

3. UNIX for Beginners Questions & Answers

Sort files to the split second

I need a similar sort, I need to sort the directory by time, but time needs to be to the second or smaller. Using ls -lt but that is only to the minute. (3 Replies)
Discussion started by: mwlaursen
3 Replies

4. Shell Programming and Scripting

Split and rename files

Hello, Need to split files into n number of files and rename the files Example: Input: transaction.txt.1aa transaction.txt.1ab ...... Output: transaction.txt.1 transaction.txt.2 transaction.txt.3 (3 Replies)
Discussion started by: krux_rap
3 Replies

5. Shell Programming and Scripting

Split a files into many files when condition

Hi Everyone, file.txt +++ a b c +++ d +++ asdf fefe fff Would like to have the output: file1.txt (22 Replies)
Discussion started by: jimmy_y
22 Replies

6. Shell Programming and Scripting

split a file into many files

Hello, Here is another one. The file type is almost same, many lines and many fields. What I need to do is to extract each line of old file and make it a new file, and in the new file, the field1 will be file name and the rest of field will be transpose to line. Say, 1, field1 field2 ... (8 Replies)
Discussion started by: ssshen
8 Replies

7. UNIX for Dummies Questions & Answers

to split gz files

Hi, I want to know how to split a gz file ( with out uncompressing it ) Eg:- split -b 10m file.gz (2 Replies)
Discussion started by: daptal
2 Replies

8. UNIX for Dummies Questions & Answers

split files into specified number of output files

Hi everyone, I have some large text files that I need to split into a specific number of files of equal size. As far as I know (and I don't really know that much :)) the split command only lets you specify the number of lines or bytes. The files are all of a different size, so the number of... (4 Replies)
Discussion started by: Migrainegirl
4 Replies

9. UNIX for Dummies Questions & Answers

Split a file into 2 or more files

Dear friends: I have a datafile contains 1 to 40 lines or i can be varied between 1 to 40. I want to split the datafile into smaller files: if the datafile has 40 lines or more, file1 contains line 1 to 12 file2 contains line 13 to 25 file3 contains line 26 to 28 file4 contains line 29... (4 Replies)
Discussion started by: bobo
4 Replies

10. UNIX for Advanced & Expert Users

Split n then concatenate files.

I have a file which has 350,000 records. I want all of these in 1 excel sheet file(around 6 worksheets) I used the below command to split it. split -64000 Creditratingsdata.xls credits Now i am having problems of appending into 1 excel file. I even went to the extent of trying. (cat... (4 Replies)
Discussion started by: praveen.pinto
4 Replies
Login or Register to Ask a Question