[Solved] Help with Sort command (ksh)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Help with Sort command (ksh)
# 1  
Old 04-07-2012
[Solved] Help with Sort command (ksh)

hello everyone,

I have file with de-limited values in random order shown below, where C1V0 represents column1 value1,
C2V0 represents column2 value 2, and so on.
Column0 is a constant value which i didn't represent in the sample input format.
Column1 is a numeric column.
Column2 is a timestamp (yyyy-mm-dd hh:mm:ss)
Column3 is numeric column.
And also all C3V0 values are one and the same. And all C1V1 values are same etc.
Code:
C1V0"C2V0"C3V0"
C1V0"C2V0"C3V5"
C1V0"C2V0"C3V2"
C1V0"C2V1"C3V0"
C1V0"C2V1"C3V4"
C1V2"C2V0"C3V1"
C1V2"C2V0"C3V0"
C1V0"C2V1"C3V2"
.
.
.

I'm using this sort command
Code:
sort -o output.dat -t '"' -n +1 +2 +3 "$input_file"

And it gives me o/p as : Smilie
Code:
C1V0"C2V0"C3V0"
C1V0"C2V1"C3V0"
C1V0"C2V0"C3V1"
C1V0"C2V1"C3V1"
C1V0"C2V0"C3V2"
C1V0"C2V1"C3V2"
.
.
.

But I want to get the output as :

Code:
C1V0"C2V0"C3V0"
C1V0"C2V0"C3V1"
C1V0"C2V0"C3V2"
C1V0"C2V0"C3V3"
C1V0"C2V0"C3V4"
C1V0"C2V0"C3V5"
C1V0"C2V1"C3V0"
C1V0"C2V1"C3V1"
C1V0"C2V1"C3V2"
C1V1"C2V0"C3V0"
C1V1"C2V0"C3V1"
.
.
.

what change should i do to get the expected output?

---------- Post updated at 03:54 PM ---------- Previous update was at 01:56 PM ----------

never min got my solution.
Code:
sort -o output.dat -t '"' -d +1n -2 +2 -3 +3n -4 "$input_file"


Last edited by radoulov; 04-07-2012 at 08:36 AM.. Reason: Change quote tags to code (Scrutinizer), Marked as solved (radoulov)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Need help understanding ksh scripting.

Can any one please tell me where the error in below script. Output is not as per my requirement. if condition not comparing the result of record count of a file with 1. where is the pbm in my script? Appreciate your help.. #!/bin/ksh #Module- #Summary- To move the file to direcotries if... (9 Replies)
Discussion started by: shivadanam
9 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Size (Sort files using ...)

-rw-r--r-- 1 oracle oinstall 4 Jan 17 16:23 a -rw-r--r-- 1 oracle oinstall 212 Jan 17 17:51 amar -rw-r--r-- 1 oracle oinstall 32 Jan 17 17:30 b -rw-r--r-- 1 oracle oinstall 246 Jan 17 15:40 h1.tar.gz Hi, I want combination of linux command to sort out the line which has 32k size. ... (5 Replies)
Discussion started by: karthick nath
5 Replies

3. Shell Programming and Scripting

[Solved] sort on numeric part of field

I have ran into a heavy case of PEBCAK*) and could need some advice on what i do wrong: OS is Linux (kernel 2.6.35), sort --version reports "8.5" from 2010, shell is ksh. Originally i had a file with with the following structure: hdisk1 yyy hdisk2 yyy hdisk3 yyy hdisk4 yyy hdisk5 yyy... (2 Replies)
Discussion started by: bakunin
2 Replies

4. Shell Programming and Scripting

[Solved] KSH: Array/If Help

RedHat 5 KSH I am creating an array, and then using case to go through and count for specific words. Then the count gets stored as an expression. string='ftp rcp rsh telnet ftp ftp' set -A myarray $string FTPCOUNT="0" for command in ${myarray} do case $command in ftp) FTPCOUNT=`expr... (2 Replies)
Discussion started by: nitrobass24
2 Replies

5. Shell Programming and Scripting

[Solved] cp command with dollar variable in ksh

hi, I have been trying to acheive the following task for a while now, but failed.. Need help, experts please help! This is what I am trying to do: - I am writing to a flat file the name of the source to be copied and the destination path as to where it is to be copied to. Sample flat file:... (7 Replies)
Discussion started by: abdulhusein
7 Replies

6. Shell Programming and Scripting

[Solved] AIX ksh script -d <- what does it mean?

I'm looking at a line in a script: && DRROOT="/dir1" || DRROOT="/dir2" I'm trying to understand it. Is there a "-d" command and is it seeing if /dir1 exists and, if so, set an environment variable named DRROOT to "/dir1", else set DRROOT to "/dir2" ? Thanks, -dog ---------- Post... (0 Replies)
Discussion started by: landog
0 Replies

7. Shell Programming and Scripting

[SOLVED] Sort on multiple keys

Can you guys pls take a look at this. I need to sort this list of numbers as follows: 2nd col first, then 1st col, then 3rd col, all in reverse (highest to lowest). I'm doing this: sort -k 2,2nr -k 1,1nr -k 3,3gr but, as you see, the 3rd col does not get sorted properly. Any idea... (0 Replies)
Discussion started by: mamboknave
0 Replies

8. Shell Programming and Scripting

[SOLVED] Scope of KSH Variable in Perl?

cat test.ksh #!/usr/bin/ksh VAR="Dear Friends \n How are you? \n Have a nice day \n" export VAR echo "Inside test.ksh"; ./test.pl cat test.pl #!/usr/bin/perl print "Inside test.pl \n"; print "$VAR"; Output: ./test.ksh Inside test.ksh Inside test.plWhat I want to achieve is, I... (1 Reply)
Discussion started by: dahlia84
1 Replies

9. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

10. Shell Programming and Scripting

ksh ./sort.sh: not found

I've a simple .sh file: #!/bin/ksh sort -t: -k 1.13,1.13 -k 1.16,1.29 sort.txt > output.txt When i try to run this sort.sh file ./sort.sh it gives me the error: ksh: ./sort.sh: not found I've tried the following: 1) echo $SHELL /bin/ksh 2) echo $PATH... (4 Replies)
Discussion started by: kajal_ind
4 Replies
Login or Register to Ask a Question