sorting/arrangement problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sorting/arrangement problem
# 8  
Old 05-25-2007
Quote:
Originally Posted by Abhishek Ghose
Hi,

I made small change to the code posted by Ygor...and that will apply to solution by Aigles too (remember, my problem is reassigning $4 doesnt modify $0). Heres the changed code:

awk 'BEGIN{FS=":"}{str=""; for(j=1;j<=NF;++j) str=sprintf("%s%s",str,$j)} (v[str]=="")||(v[str]>$4){v[str]=$4;a[str]=$0}END{for(i in a)print a[i]}' file1


Here are the tweaks:
(1) Now I have a new variable "str" - this doesnt have the 4th column values
(2) In the condition part, now I check for (v[str]=="") instead of (!v[str]) --- the latter throws an error on my system.

Thanks to everyone for the effort....

Regards, Abhishek
Sorry...the corrected code is (missed the conditional in the for loop):
awk 'BEGIN{FS=":"}{str=""; for(j=1;j<=NF;++j) if(j!=4) str=sprintf("%s%s",str,$j)} (v[str]=="")||(v[str]>$4){v[str]=$4;a[str]=$0}END{for(i in a)print a[i]}' file1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problem with sorting in shell script

Hi, I have the following list: 42A 42AA 42B 42BB 42AAA 42BBB 49A 49AA 49B 49AAA 49BB I need it to be sorted as following: 42A 42B (2 Replies)
Discussion started by: sairamtejaswi
2 Replies

2. UNIX for Advanced & Expert Users

Sorting problem

I have data like this in file Now I have to sort using second column(usage) and i should get first column against it post sorting please provide input (2 Replies)
Discussion started by: mirwasim
2 Replies

3. Shell Programming and Scripting

Help with data re-arrangement problem facing

Input file: <symbol>Q9Y8G1</symbol> <name>Q9Y8G1_EMENI</name> <symbol>Q6V953</symbol> <symbol>Q5B8K1</symbol> <name>Q6V953_EMENI</name> <symbol>G1A416</symbol> <name>G1A416_9FUNG</name> <symbol>D4N894</symbol> <name>D4N894_PLEER</name> <symbol>B0FFU4</symbol>... (13 Replies)
Discussion started by: cpp_beginner
13 Replies

4. Shell Programming and Scripting

Help to data re-arrangement problem

Input file <data id>="1">\ </data>\ <data id>="2">\ </data>\ <code>="1" target="2">\ </code>\ <data id>="1">\ </data>\ <data id>="2">\ </data>\ <code>="1" target="2">\ </code>\ <data id>="1">\ </data>\ <data id>="2">\ </data>\ <code>="1" target="2">\ </code>\ (2 Replies)
Discussion started by: cpp_beginner
2 Replies

5. UNIX for Dummies Questions & Answers

Sorting problem

1) I need to reverse sort the text from lit.csv (bellow) by the second column, then save the last five lines in a text file text.txt but I'm doing something wrong so any help would be much appreciated. I've been trying to use this: sort --field-separator=; -b -k2g,2 lit.csv -o text.txt 2)... (4 Replies)
Discussion started by: Kova
4 Replies

6. UNIX for Dummies Questions & Answers

Sorting file with columns (problem)

Hi all! I am new to Unix programming so bare with me please :). I have saved the output of my results in a file called testfile which contains 3 columns a 15 rows. e.g. 175 754 abvd 948 454 fewf 43 754 fewc 6 734 feww xxx xxx xxxx I want to sort the contents of this file... (10 Replies)
Discussion started by: daelas
10 Replies

7. Shell Programming and Scripting

Sorting problem (SunOS 5.9 / KSH).

Hi, Can someone tell me why the "LargeFile" is coming first before the smaller files. Is there any way to list the files based on size column. ls -g| sort -k 4 -rw-r--r-- 1 user 6117910528 Apr 28 15:04 LargeFile -rw-r--r-- 1 user 6136832 May 30 07:23 my_20080530.tar -rw-r--r-- ... (2 Replies)
Discussion started by: kesari
2 Replies

8. UNIX for Dummies Questions & Answers

Sorting problem

Hai , In unix we are going to sort it out all the directories and files based on size of the file. For that we have to use this command ls -al | sort +4nr. If we are giving this command means it will show all the records in a descending order....when I am checking one file bytes its... (4 Replies)
Discussion started by: cool4naren
4 Replies

9. HP-UX

Sorting problem....

hey mate. ive got a sorting problem that i would like to share... i made a script that sorts the bdf command and redirected the output to a file. the output of the file is: 691416 34% / 851552 7% /stand 7203048 31% /var 23637584 26% /var/adm/crash 2968864 ... (4 Replies)
Discussion started by: jarod004
4 Replies

10. Shell Programming and Scripting

Problem in sorting the file

file format is word filename no.of occurances ------------------------------ wish f3.txt 2 wish f2.txt 1 cold f1.txt 5 cold f2.txt 3 cold f1.txt 3 cold e.txt 3 gold f1.txt 7 gold f3.txt 3 rush e.txt 2 itz abt building a search index for every word in the files given as input the... (1 Reply)
Discussion started by: vishnu_vaka
1 Replies
Login or Register to Ask a Question
DSDP(1) 						      General Commands Manual							   DSDP(1)

NAME
dsdp5 - semidefinite program solver SYNOPSIS
dsdp5 [options] filename maxcut [options] filename theta filename DESCRIPTION
This manual page documents briefly the dsdp5, theta and maxcut commands. dsdp5 -- interface to solve general semi-definite programs maxcut -- solves a SDP relaxation of the maximum cut problem theta -- solves the Lovasz thetha problem OPTIONS
A summary of options is included below. For a complete description, see /usr/share/doc/dsdp-doc. -help Show summary of options. -v, --version Show version of program. -print print information at each k iteration (default 10) -save filename of solution file in SDPA format -fout filename to print standard monitor to a file -y0 filename for initial solution file -benchmark filename to file containing names of SDPA files -directory path to directory containing benchmark SDPA files -suffix suffix to add to each benchmark problem name -dloginfo print more information for higher numbers (default 0) -dlogsummary print timing information (default 1 - enabled) -gaptol gap tolerance parameter, stop when relative duality gap less than this gap (default 1e-6) -r0 if nonnegative, initialize S by adding this multiple of the identity matrix (default -1) -penalty penalize dual infeasibility (default 1e10) -boundy bound for variables y (default 1e7) -maxit set maximum iterates (default 200) -zbar Upper bound for dual solution (default 1e10) -mu0 if positive, set initial barrier parameter (default -1) -rho Potential parameter as multiple of dimension (default 3) -drho Use dynamic rho strategy (default 1) -pnormtol stop only if pnorm less than (default 1e30) -reuse Reuse the Schur Matrix this many times (default 4) -dobjmin apply a known lower bound for the objective at solution as a constraint. -bigM if positive, modify algorithm to make dual infeasibility positive with a large associated cost (default 0) -dloginfo print more information for higher numbers (default 0) -params filename to read selected options from a file SEE ALSO
glpsol(1), The programs are documented fully in the accompanying .pdf and html documentation which can be found in /usr/share/doc/dsdp-doc if the dsdp-doc package is installed. AUTHOR
dsdp was written by Steven J. Benson <benson@mcs.anl.gov> and Yinyu Ye <yinyu-ye@stanford.edu> This manual page was written by Soeren Sonnenburg <sonne@debian.org>, for the Debian project (but may be used by others). August 1, 2007 DSDP(1)