Thanks to both of you for doing it. It working now and extremely sorry for delaying the response as I was trying to do it from sql. I am using HP UX and may be prinf has 3000 byte limitation.
-S was not working in my case therefore I have change the code in different way. The updated is:
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 -1 file*| sort -r -n -k5) # it is used to sort the file with size.
Thanks to both of you for doing it. It working now and extremely sorry for delaying the response as I was trying to do it from sql. I am using HP UX and may be prinf has 3000 byte limitation.
Ah thanks, so print is working, but printf is not. Something to keep in mind..
Quote:
-S was not working in my case therefore I have change the code in different way. The updated is:
Code:
[..]
' $(ls -1 file*| sort -r -n -k5) # it is used to sort the file with size.
Yes the -S, -A and -k options for the ls command only made it to the POSIX standards in issue 7 (2008.1). So OS that adhere to earlier POSIX standards may not understand these command flags..
The command you provide will not work correctly. Note that it uses the -1 option (one name per line) and not the -l (long format) option. Therefore there is no column 5 and the sort will not work..
Try this alternative instead:
Code:
[..]
' $(ls -nd * | sort -rn -k5 | awk '{print $NF}') # it is used to sort the file with size.
Note that this also only works with files without spaces...
Also note, that I used the -n option here instead of the -l option, sometimes ls gets in trouble when user/group names are too long and then that can make mess up the ls output columns. This can be avoided by printing UID and GID, rather than the names..
Last edited by Scrutinizer; 12-31-2014 at 05:23 AM..
tee outfile1 outfile2 outfile3 outfile4 < /dev/null
to your script before the awk command to be sure that all of your output files exist and that those that the awk script doesn't write to will be of size zero.
Have you tried Scrutinizer's updated script with the final line being:
Code:
' $(ls -nd file* | sort -rn -k5 | awk '{print $NF}') # list files in decreasing file size order
with any files larger than 3000 bytes yet? I know that there are some versions of awk where the maximum string size that can be processed is LINE_MAX (probably 2048 on HP-UX) bytes or a little more (maybe 3000 in your case).
In the future, it would help all of us if instead of saying things like "-S was not working" you would say something more like "When I tried using the -S option, I got the following diagnostic:" and then show us the actual diagnostic that was produced (in CODE tags).
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)
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)
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)
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)
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)
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)
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)
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)