Split using AWK - out file name control


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split using AWK - out file name control
# 1  
Old 07-09-2012
Split using AWK - out file name control

Hi Gurus,
I am using following code to split a big file into pieces.
Code:
awk '!((NR-1)%ln){close(f);f=name i++}{print>f}' i=1 name=my_file ln=25000 main_file

The output that is produces is something like this -

Code:
my_file2
my_file1
my_file4
my_file3
my_file5
my_file7
my_file6
my_file9
my_file8
my_file10
my_file12
my_file11

But I want output like this :
Code:
my_file_aa
my_file_ab
my_file_ac
my_file_ad
.......

I have been trying without any breakthrough..

Please suggest.
# 2  
Old 07-09-2012
why not use the unix
Code:
split

command?
# 3  
Old 07-10-2012
The split is taking more time.
And I've embedded two logics in splitting the file. Only one logic i.e. based on number of lines, is shown here.
The other logic is to check a column for a specific value like $5="Commit".
So I can't use split.
Please help with AWK itself.
# 4  
Old 07-10-2012
Try something like...
Code:
$ seq 1 1 27 | awk '{printf "%s\t%c%c\n",$1,int(($1-1)/26)+97,int(($1-1)%26)+97}'
1       aa
2       ab
3       ac
4       ad
5       ae
6       af
7       ag
8       ah
9       ai
10      aj
11      ak
12      al
13      am
14      an
15      ao
16      ap
17      aq
18      ar
19      as
20      at
21      au
22      av
23      aw
24      ax
25      ay
26      az
27      ba

$

It's limited to maximum 26 * 26 = 676 = "zz"...
Code:
$ seq 670 1 680 | awk '{printf "%s\t%c%c\n",$1,int(($1-1)/26)+97,int(($1-1)%26)+97}'
670     zt
671     zu
672     zv
673     zw
674     zx
675     zy
676     zz
677     {a
678     {b
679     {c
680     {d

$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split file using awk

I need to split the incoming source file in to multiple files using awk. Split position is (6,13) : 8 positions All the records that are greater than 20170101 and less than or equal to 20181231 should go in a split file with file name as source... (11 Replies)
Discussion started by: rosebud123
11 Replies

2. Shell Programming and Scripting

awk file split

Hi all, First of all I' like to mention that I'm pretty new to unix scripting. :( I'm trying to split an large xml with awk and rename it based on the values of two attributes. Example XML <RECORD> <element1>11</element1> <element2>22</element2> <element3>33</element3>... (18 Replies)
Discussion started by: f0usk4s
18 Replies

3. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

4. Shell Programming and Scripting

Split a file with awk

Hi! I have a file like this: a,b,c,12,d,e a,b,c,13,d,e a,b,c,14,d,e a,b,c,15,d,e a,b,c,16,d,e a,b,c,17,d,e I need to split that file in two: If field 4 is equal or higher than 14 that row goes to one file and if it is equal or higher than 15 to another. Can anyone point me in the... (2 Replies)
Discussion started by: Tr0cken
2 Replies

5. Shell Programming and Scripting

AWK File Split

Hi All, Input.txt XYZONEABC                  CZXTWOJJJ KKKSIXOOO asdfhajlsdhfajs asdfasfasdf Output Files: ONE.txt XYZONEABC                 TWO.txt CZXTWOJJJ SIX.txt KKKSIXOOO I had a script (2 Replies)
Discussion started by: kmsekhar
2 Replies

6. Shell Programming and Scripting

How to split a file using AWK?

Hello, I have a file like the following: david,a,b,c,20,r thomas,a,b,c,30,r willaiam,a,b,c,80,r barbara,a,b,c,100,r I would like to split the file into other files using a condition for the contents of column 5. The condition should be a if the contents of column 5 is in a range... (4 Replies)
Discussion started by: keenboy100
4 Replies

7. Shell Programming and Scripting

split a file using awk

Hi , I just need to split a file and outputfiles are redirected to gzip file need: Input file - A.gz content of A.gz is 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200212|sdfdf 100|sfdds|dffdds|200212|sdfdf... (3 Replies)
Discussion started by: mohan_xunil
3 Replies

8. UNIX for Dummies Questions & Answers

Shift the control between files using Split

In linux terminal there is a command "split" which splits the terminal for viewing multiple files. Now my question is how to shift control from one file to other when split is used? (1 Reply)
Discussion started by: manoj.b
1 Replies

9. Shell Programming and Scripting

split file with awk

I did a lot of search on this forum on spiting file; found a lot, but my requirement is a bit different, please guide. Master file: x:start:5 line1:23 line2:12 2:90 x:end:5 x:start:2 45:56 22:90 x:end:2 x:start:3 line1:23 line2:12 x:end:3 x:start:2 line5:23 (1 Reply)
Discussion started by: uwork72
1 Replies

10. 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
Login or Register to Ask a Question