Sponsored Content
Full Discussion: Dynamically split file
Top Forums Shell Programming and Scripting Dynamically split file Post 302961715 by coweb on Wednesday 2nd of December 2015 06:16:49 PM
Old 12-02-2015
Hi Don

No that's not a homework/coursework (I wish I were a studentSmilie)
The fields are separated with tabs (I have another file where the fields are separated with commas).

Please check below a sample of the file that has been generated and it will be used as input:
Code:
25467Quill	948
38120Sarra	289
75283Moonstone	734
18359Mineral	400
63456Breeze	1022
78345Oxford	158
78456Duke	278
12726Iris	540
43361Velvet	195
65611Boutique	655
37556Exotica	452
11590Olana	794
70146Felicity	245
44498Quartz	852
61455Bella	693

The output files should be as below:
FileA
Code:
25467Quill	948
11590Olana	794

FileB
Code:
38120Sarra	289
78345Oxford	158
12726Iris	540
70146Felicity	245
61455Bella	693

FileC
Code:
75283Moonstone	734
65611Boutique	655

FileD
Code:
18359Mineral	400
78456Duke	278
43361Velvet	195
37556Exotica	452

FileE
Code:
63456Breeze	1022
44498Quartz	852

The OS is RedHat5 and I am using bash shell.

So far I 've tried the following:
Code:
split -l 2000 Input_file.txt

The above does not meet my needs as I am created 5 file with 2000 lines in each

Code:
awk '{print > "NewFile" ((NR-1)%x)}' x=5 Input_file.txt

That one is more close to what I need, however, the new entries are not checking the file with the lowest quantity before they will be added.

Last edited by coweb; 12-02-2015 at 07:28 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

dynamically linked file

Hi friends , how do i view a dynamically linked file in unix ? its there on other system and do i have to ftp it in ASCII format or binary ? and after the ftp how do i view it ? thanks in advance veeras (1 Reply)
Discussion started by: sveera
1 Replies

2. UNIX for Advanced & Expert Users

dynamically linked file

Hi friends, i have a dynamically linked file on my solaris system.this is script that runs regularly. How can i read the contents of that ? when i tried to say "vi filename " then it says executable and nothing is seen. Please help. thanks in advance Veera (5 Replies)
Discussion started by: sveera
5 Replies

3. Shell Programming and Scripting

dynamically split the records

Hi, I was wandering would it be possible to split the record dynamically based on the certain values, for an instance i have a file with record with predefined split value i.e 10 col1 col2 col3 col4 ------------------------ aaaa bbbb 2 44aaaabbbb55cccddd1110 mmn xnmn 3... (6 Replies)
Discussion started by: braindrain
6 Replies

4. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

5. Shell Programming and Scripting

Spliting the file dynamically

i am creating the file , when this file reaches the size 2 GB, i need one message or fire (4 Replies)
Discussion started by: kingganesh04
4 Replies

6. Shell Programming and Scripting

Dynamically locating a file

Hi, I have a requriement where in I need to install a s/w by executing the installable file through a script. The script currently contains the path of the installable file. I need to now update the script accordingly such tht it identifies the location of the installable file automatically and... (1 Reply)
Discussion started by: yoursdavinder
1 Replies

7. UNIX for Dummies Questions & Answers

Read a file dynamically

Hi my requriment is read the file name dynamically my code is #!/bin/sh file="/c/work/loan/" Header_Trailer_move() { sed '1d;$d' $file| cat >sam.txt } Header_Trailer_move in above given path my list of files or there i have to read file dyanamically when i entered particular file name... (2 Replies)
Discussion started by: sgoud
2 Replies

8. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

9. Shell Programming and Scripting

Dynamically creating file names from portions of another file name

Not sure how to do the following, but any help would be appreciated. Has to be done using C shell (sorry about that). I have about 300 files that I need this done for, but I am only going to give one example. I will just need to know how to execute your solution through some type of loop to get... (2 Replies)
Discussion started by: jclanc8
2 Replies

10. Shell Programming and Scripting

Split file Dynamically

Hello , I have a flat file ( comma separated ) and want to split dynamically . If I provide input 3 then rows 1,4,7 will o/p to a file and rows 2,5,8 will redirect to 2nd file and 3,6,9 rows will go to 3rd file So 3 files will be generated . Could it be possible in Unix? (2 Replies)
Discussion started by: Pratik4891
2 Replies
All times are GMT -4. The time now is 07:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy