Sponsored Content
Top Forums Shell Programming and Scripting Split File based on number of rows Post 302926365 by Chubler_XL on Sunday 23rd of November 2014 05:37:42 PM
Old 11-23-2014
Here is an awk script to split file into pieces < MAX bytes without splitting lines:

Code:
awk \
   -v MAX=1000000000 \
   -v oname="${3}/TT_$2" \
   -v digits=2 \
'
function suffix(val,ret) {
 for(i=digits; i; i--) {
     ret = sprintf("%c", 97 + (val%26)) ret
     val=int(val/26)
 }
 return ret
}
BEGIN {sz=MAX}
{
  line_len=length()+1
  if (sz + line_len > MAX) {
     if(outfile != "") {
         close(outfile)
         print "  " row " " sz " " outfile
     }
     outfile=(oname?oname:FILENAME) suffix(Fnum++)
     row=sz=0
  }
  row++
  sz+=line_len
  fs+=line_len
  print > outfile
}
END {
 print "  " row " " sz " " outfile
 print "  " NR " " fs " total"
}' "$ifile"

This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting file based on number of rows

Hi, I'm, new to shell scripting, I have a requirement where I have to split an incoming file into separate files each containing a maximum of 3 million rows. For e.g: if my incoming file say In.txt has 8 mn rows then I need to create 3 files, in which two will 3 mn rows and one will contain 2... (2 Replies)
Discussion started by: wahi80
2 Replies

2. Shell Programming and Scripting

split based on the number of characters

Hello, if i have file like this: 010000890306932455804 05306977653873 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC30693599000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202011302942311 010000890306946317387 05306977313623 0520080417010520ISMS SMT... (6 Replies)
Discussion started by: chriss_58
6 Replies

3. Shell Programming and Scripting

Split File Based on Line Number Pattern

Hello all. Sorry, I know this question is similar to many others, but I just can seem to put together exactly what I need. My file is tab delimitted and contains approximately 1 million rows. I would like to send lines 1,4,& 7 to a file. Lines 2, 5, & 8 to a second file. Lines 3, 6, & 9 to... (11 Replies)
Discussion started by: shankster
11 Replies

4. Shell Programming and Scripting

Split single file into multiple files based on the number in the column

Dear All, I would like to split a file of the following format into multiple files based on the number in the 6th column (numbers 1, 2, 3...): ATOM 1 N GLY A 1 -3.198 27.537 -5.958 1.00 0.00 N ATOM 2 CA GLY A 1 -2.199 28.399 -6.617 1.00 0.00 ... (3 Replies)
Discussion started by: tomasl
3 Replies

5. Shell Programming and Scripting

Average calculation based on number of rows

Dear users, I need your support, I have a file like this: 272134.548 6680572.715 272134.545 6680572.711 272134.546 6680572.713 272134.548 6680572.706 272134.545 6680572.721 272134.543 6680572.710 272134.544 6680572.715 272134.543 6680572.705 272134.540 6680572.720 272134.544... (10 Replies)
Discussion started by: Gery
10 Replies

6. UNIX for Dummies Questions & Answers

count number of rows based on other column values

Could anybody help with this? I have input below ..... david,39 david,39 emelie,40 clarissa,22 bob,42 bob,42 tim,32 bob,39 david,38 emelie,47 what i want to do is count how many names there are with different ages, so output would be like this .... david,2 emelie,2 clarissa,1... (3 Replies)
Discussion started by: itsme999
3 Replies

7. UNIX for Dummies Questions & Answers

Sum the rows number based on first field string value

Hi, I have a file like this one h1 4.70650E-04 4.70650E-04 4.70650E-04 h2 1.92912E-04 1.92912E-04 1.92912E-04 h3A 3.10160E-11 2.94562E-11 2.78458E-11 h4 0.00000E+00 0.00000E+00 0.00000E+00 h1 1.18164E-12 2.74150E-12 4.35187E-12 h1 7.60813E-01 7.60813E-01 7.60813E-01... (5 Replies)
Discussion started by: f_o_555
5 Replies

8. UNIX for Dummies Questions & Answers

Command to split the files based on the number of lines in it

Hello Friends, Can anyone help me for the below requirement. I am having a file called Input.txt. My requirement is first check the count that is wc -l input.txt If the result of the wc -l Input.txt is less than 10 then don't split the Input.txt file. Where as if Input.txt >= 10 the split... (12 Replies)
Discussion started by: malaya kumar
12 Replies

9. Shell Programming and Scripting

How to split a file based on pattern line number?

Hi i have requirement like below M <form_name> sdasadasdMklkM D ...... D ..... M form_name> sdasadasdMklkM D ...... D ..... D ...... D ..... M form_name> sdasadasdMklkM D ...... M form_name> sdasadasdMklkM i want split file based on line number by finding... (10 Replies)
Discussion started by: bhaskar v
10 Replies

10. UNIX for Dummies Questions & Answers

Split file based on number of blank lines

Hello All , I have a file which needs to split based on the blank lines Name ABC Address London Age 32 (4 blank new line) Name DEF Address London Age 30 (4 blank new line) Name DEF Address London (8 Replies)
Discussion started by: Pratik4891
8 Replies
CTFMERGE(1)						    BSD General Commands Manual 					       CTFMERGE(1)

NAME
ctfmerge -- merge several CTF data sections into one SYNOPSIS
ctfmerge [-fgstv] -l label -L labelenv -o outfile file ... ctfmerge [-fgstv] -l label -L labelenv -o outfile -d uniqfile [-g] [-D uniqlabel] file ... ctfmerge [-fgstv] -l label -L labelenv -o outfile -w withfile file ... ctfmerge [-g] -c srcfile destfile DESCRIPTION
The ctfmerge utility merges several CTF data sections from several files into one output file, unifying common data. The following options are available: -f Match global symbols to global CTF data. -g Don't delete the original debugging sections. -s Use the .dynsym ELF section instead of the .symtab ELF section. -t Make sure that all object files have a CTF section. -v Enable verbose mode. -l label Sets the label as label. -L labelenv Instructs ctfmerge to read the label from the environment variable labelenv. -o outfile Use outfile to store the merged CTF data. -d uniqfile Uniquify against uniqfile. -d uniqlabel Uniquify against label uniqlabel -w withfile Additive merge with withfile. -c srcfile destfile Copy CTF data from srcfile into destfile. EXIT STATUS
The ctfmerge utility exits 0 on success, and >0 if an error occurs. SEE ALSO
ctfconvert(1), ctfdump(1) HISTORY
The ctfmerge utility first appeared in FreeBSD 7.0. AUTHORS
The CTF utilities came from OpenSolaris. BSD
July 7, 2010 BSD
All times are GMT -4. The time now is 03:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy