Need help on merging


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help on merging
# 8  
Old 12-29-2014
Five files? Do you call it like this
Code:
...
' $(ls -drS test[1-5])

What does
Code:
ls -drS test[1-5]

produce?
# 9  
Old 12-29-2014
I have call it '$(ls -drS test*). Though with modification i have able to pull it off. But a new problem has occured now. it showing the below error:

awk: Format item %s cannot be longer than 3,000 bytes.

I know awk cannot read more than 3000 byte. Can this be rectify some how?
# 10  
Old 12-29-2014
Please get used to post the context of the error producing code.

Without seeing what script/code you ran we can only guess that there's a quote or a comma missing in a printf statement.
# 11  
Old 12-29-2014
This is what I am using :
Code:
awk '
  BEGIN {
    n=4
    m=1
  }
  FNR==1 {
    if(NR>1) {
      A[m]+=sz
      f="outfile" m
      printf "%s",s>f
      m=1
      for(i=2; i<=n; i++)
        if(A[m]>A[i])
          m=i
      s=x
      sz=0
    }
  }
  {
    s=s $0 ORS 
    sz+=length
  }
  END {
    if(NR>1)printf "%s",s>f
  }
' $(ls -dr sample*)


Last edited by Don Cragun; 12-29-2014 at 07:10 AM.. Reason: Add CODE tags.
# 12  
Old 12-30-2014
Can any one help?
# 13  
Old 12-30-2014
Scrutinizer's code (and your modification of it) are reading files into memory line by line but writing entire input files with one printf statement. For any input file larger than 3000 (or whatever your system's size limit is, if it has a limit) bytes, the writes will fail.

That can be fixed by copying a line at a time from an input file to an output file as you read each instead of copying entire input files in single printf calls.

But, to even out the four output file sizes (which you said was a primary goal), Scrutinizer's code depends on copying the largest remaining input file to an output file first. Your modification to Scrutinizer's code (sorting files by reverse alphabetical filename instead of sorting by decreasing file size) will not meet you goal of producing similar sized files unless all of your input files are about the same size. You said:
Quote:
I have call it '$(ls -drS test*). Though with modification i have able to pull it off. ...
How did changing:
Code:
$(ls -drS file*)

to:
Code:
$(ls -dr file*)

enable you to "pull it off"? I don't see why this change would have any effect on getting the error you're seeing. Did I miss some other change you made to Scrutinizer's suggested code?

Changing Scrutinizer's code to copy a line at a time instead of a file at a time is pretty straightforward. But, doing that without understanding why you found sorting by name instead of sorting by size necessary would be a waste of time. What additional constraint is there that you haven't explained to us that requires a different order of input files in the merged output files?
# 14  
Old 12-30-2014
I addition to what Don Cragun said, try this modification:
Code:
awk '
  BEGIN {
    n=4
    m=1
  }
  FNR==1 {
    if(NR>1) {
      A[m]+=sz
      f="outfile" m
      print s>f
      m=1
      for(i=2; i<=n; i++)
        if(A[m]>A[i])
          m=i
      s=x
      sz=0
    }
  }
  {
    s=s (FNR>1?ORS:x) $0 
    sz+=length
  }
  END {
    if(NR>1)print s>f
  }
' $(ls -drS file*)

I think the 3000 byte limit is specific for the printf statement in certain awk implementations (HPUX?)
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Interval merging

I do have a file (file1) with a specified interval of 500 counts file1 0 500 500 1000 1000 1500 1500 2000 2000 2500 2500 3000 3000 3500 3500 4000 4000 4500 4500 5000 5000 5500 5500 6000 6000 6500 6500 7000 7000 7500 7500 8000 (3 Replies)
Discussion started by: Kanja
3 Replies

2. Shell Programming and Scripting

Merging 2 Arrays

I am trying to create a script that combines 2 arrays: #!/bin/bash read -a unix #(a c e g) read -a test #(b d f) #now I want to merge ${unix} with ${test}, one after another such that the result would be: (abcdefg) #I've tried quite a few options and can't seem to make it work (5 Replies)
Discussion started by: pbmitch
5 Replies

3. Shell Programming and Scripting

Merging

Hi, I have searched the forums for a solution but I haven't found a perfect answer, and I'm a bit of a novice, so I hope someone can help: I have 2 files: file1: Chr1 139311 1/1:37,3,0:19 Chr1 139350 1/1:67,6,0:19 Chr1 139404 1/1:0,0,0:7 Chr1 152655 0/1:0,0,0:3 Chr1 152718... (2 Replies)
Discussion started by: ljk
2 Replies

4. Shell Programming and Scripting

Merging two files with merging line by line

Hi, I have two files and i want to merge it like, file1.txt --------- abc cde efg file2.txt ------- 111 222 333 Output file should be, -------------- abc 111 (2 Replies)
Discussion started by: rbalaj16
2 Replies

5. Shell Programming and Scripting

merging

Hi all, I have 2 files. I want to merge a portion or column in file 2 into file 1. file 1 - not tab or space delimited B_1 gihgjfhdj| hgfkddlldjljldjlddl B_2 gihgjddshjgfhs| hgfkddlldjljldjlddl B_3 gihgjfhdj| hgfkddlldjljldjlddlhgjdhdhjdhjhdjhdjhgdj file2 -... (7 Replies)
Discussion started by: Lucky Ali
7 Replies

6. Shell Programming and Scripting

merging two files

Friends, os: redhat enterprise linux/SCO UNIX5.0 I have two files and I would like to merge on given key value. Now I have tried with join commd but it does not supporte multiple delimiters. and if records length is not fixed. join -a1 5 -a2 1 -t -o file1 file2 > outname Can any... (7 Replies)
Discussion started by: vakharia Mahesh
7 Replies

7. UNIX for Dummies Questions & Answers

Merging files

Hi i have two files say file 1 contents are A B C D E I have file2 contents are B E F G C K I want to have new file like A B (4 Replies)
Discussion started by: ssuresh1999
4 Replies

8. Shell Programming and Scripting

merging files

Thanks in advance I have 2 files having key field in each.I would like to join both on common key.I have used join but not sucessful. The files are attached here . what i Want in the output is on the key field SLS OFFR . I have used join commd but not successful. File one ======= SNO ... (6 Replies)
Discussion started by: vakharia Mahesh
6 Replies

9. Shell Programming and Scripting

Merging arrays

Hi all, I need some help in merging arrays. I have two arrays and using korn shell Array1 AB23 AB24 Array2 CD00 CD01 CD02 Elements from array 1 should always alternate with elements of arrays 2 i.e the result should look like AB23CD00 AB24CD01 AB23CD02 Any help is appreciated.... (4 Replies)
Discussion started by: jakSun8
4 Replies

10. Shell Programming and Scripting

Merging Help

Hi Gurus, I need a help in merging the files. I have nearly 7 files and the files will have time stamp in it. I need to merger these files condition is it is not necessary that all the 7 files has to be there. suppose if i have only 3 files availabe out of these 7 then i need to merge... (3 Replies)
Discussion started by: kumarc
3 Replies
Login or Register to Ask a Question