Help with split one file content into multiple different file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with split one file content into multiple different file
# 1  
Old 09-19-2011
Help with split one file content into multiple different file

Input file:
Code:
[home@perl_beginner]cat input_file.txt
data_1 2342
data_3 242
data_1 3546
data_5 458
data_10 342
data_30 42
data_10 346
content_50 48
content_1 2343

Desired output:
Code:
[home@perl_beginner]cat output_file1.txt
data_1 2342
data_3 242
data_1 3546
data_5 458
 [home@perl_beginner]cat output_file2.txt
 data_10 342
 data_30 42
 data_10 346
 content_50 48
 [home@perl_beginner]cat output_file3.txt
  content_1 2343

Condition:
1. Based on input file and split the content into multiple file that contains 4 data content in each output file.
2. All the desired output file, named as "output_file*.txt"

Based on the input file shown above, because my input file got 9 data content. Since each output file only allow 4 data content. So it will generate three output file named as "output_file1.txt, output_file2.txt, output_file3.txt".

Many thanks for any advice.
# 2  
Old 09-19-2011
Code:
split -a 1 -d -l 4 input_file.txt output_file

It will produce output_file1, output_file2, ...
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 09-19-2011
How about an awk solution...
Code:
awk '{print > "output_file" int((NR-1)/4+1) ".txt"}' file

This User Gave Thanks to shamrock For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Split a large textfile (one file) into multiple file to base on ^L

Hi, Anyone can help, I have a large textfile (one file), and I need to split into multiple file to break each file into ^L. My textfile ========== abc company abc address abc contact ^L my company my address my contact my skills ^L your company your address ========== (3 Replies)
Discussion started by: fspalero
3 Replies

2. Shell Programming and Scripting

Split a file in more files based on score content

Dear All, I have the following file tabulated: ID distanceTSS score 8434 571269 10 10122 393912 9 7652 6 10 4863 1451 9 8419 39 2 9363 564 21 9333 7714 22 9638 8334 9 1638 1231 11 10701 918 1000 6587 32056 111 What I would like to do is the following, create 100 new files based... (5 Replies)
Discussion started by: paolo.kunder
5 Replies

3. Shell Programming and Scripting

How to split file into multiple files using awk based on 1 field in the file?

Good day all I need some helps, say that I have data like below, each field separated by a tab DATE NAME ADDRESS 15/7/2012 LX a.b.c 15/7/2012 LX1 a.b.c 16/7/2012 AB a.b.c 16/7/2012 AB2 a.b.c 15/7/2012 LX2 a.b.c... (2 Replies)
Discussion started by: alexyyw
2 Replies

4. Shell Programming and Scripting

split file content into specific folders

Hi I have a large text file and I want to split its content into multiple flies. this large file contains several blocks of codes separated by a comment line for each block. this comment line represents a directory path So, when separate these blocks each into a separate file, This output... (7 Replies)
Discussion started by: turki_00
7 Replies

5. Shell Programming and Scripting

Split a file into multiple files based on first two digits of file.

Hi , I do have a fixedwidth flatfile that has data for 10 different datasets each identified by the first two digits in the flatfile. 01 in the first two digit position refers to Set A 02 in the first two digit position refers to Set B and so on I want to genrate 10 different files from my... (6 Replies)
Discussion started by: okkadu
6 Replies

6. Shell Programming and Scripting

Split the file based on the content

Arun kumar something somehting Enterting in to the line . . . . Some text text Finshing the sentence Some other text . . . . Again something somehting Enterting in to the line . . . . . . Again text text Finshing the sentence (6 Replies)
Discussion started by: arukuku
6 Replies

7. Shell Programming and Scripting

split file content

Hi All; I have input file like below name char(3) number number(3) inputfile namenumber xyz123abc509kai330 aca203 ald390afa000als303 I wanted to split like below:- output like this:- xyz123 abc509 kai330 aca203 ald390 (6 Replies)
Discussion started by: Jairaj
6 Replies

8. Shell Programming and Scripting

Help with split the file content into multiple different file

Input file content: NA_10001 XA_10081 NG_10015 AC_1321.1 . . Desired output file: ls *.txt NA_10001.txt XA_10081.txt NG_10015.txt AC_1321.1.txt cat NA_10001.txt NA_10001 cat XA_10081.txt XA_10081 (1 Reply)
Discussion started by: perl_beginner
1 Replies

9. Shell Programming and Scripting

Split one file to Multiple file with report basis in unix

Hi, Please help on this. i want split the below file(11020111.CLT) to more files with some condition. :b: 1) %s stating of the report 2) %e ending of the report example starting of the report: %sAEGONCA| |MUMBAI | :EXPC|N|D ending of the report %eAEGONCA| |MUMBAI | :EXPC 3)so the... (10 Replies)
Discussion started by: krbala1985
10 Replies

10. Shell Programming and Scripting

split file depending on content

Hi, I have a file which contains records of data. I need to split the file into multiple files depending upon the value of last field. How do i read the last field of each record in the file??? Regards, Chaitrali (4 Replies)
Discussion started by: Chaitrali
4 Replies
Login or Register to Ask a Question