Not able to sort two fields and printf not displaying the correct values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to sort two fields and printf not displaying the correct values
# 1  
Old 11-05-2015
Not able to sort two fields and printf not displaying the correct values

Not able to sorting two fileds resolved printf issue
Code:
01-1000/9|JAN
01-0000/6|MAN
01-1010/2|JAN
01-1010/2|JAN
01-1010/2|JAN
01-1000/9|JAN
01-1000/9|JAN
01-1000/9|SAA
01-1000/9|SAA
01-0000/6|SAN
01-0000/6|SAN

Code:
1.sort -t'|' -k1,1n -k2,2 file


Last edited by kalia4u; 11-05-2015 at 06:57 AM..
# 2  
Old 11-05-2015
Ad 1, try:
Code:
sort -t'|' -k1.1,1.2n -k1.4,1.7n -k1.9,1n -k2,2 file

Ad 2. You need to specify a field separator if your file is not space separated.
# 3  
Old 11-05-2015
Thanks a lot for your replay issue got resolved
# 4  
Old 11-05-2015
Note that when you're sorting field 1 as a numeric field, you are sorting the number:
Code:
01

not the string:
Code:
01-1000/9

and not the numeric value resulting from treating that string as the arithmetic expression:
Code:
1 - (1000 / 9)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printf() not displaying as it should.

Hi, I have some code. Everything works as it should, but, when I call view_all_contacts() to print the data, each line doesn't line up as it should. I get tab keys between each line. The problem code is this: printf("\n\eHere is the rest of the code: void add_contact();... (5 Replies)
Discussion started by: ignatius
5 Replies

2. Shell Programming and Scripting

Comparing fields of two files and displaying results

Hello , I am trying to compare two files i.e one master file and the other exclusion file. If the second field of masterfile is oracle8 then I need to compare the 3rd field of master file with the 1st field of all the rows of exclusion file else I need to compare 2nd field from master file with... (2 Replies)
Discussion started by: rahul2662
2 Replies

3. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

4. Shell Programming and Scripting

Correct incomplete fields separated by new lines

Hello Friends, I have an issue with a csv file that is separated by comma. The file should have 5 fields every time. The record delimiter of the file is \r\n but we are seeing that in few records the address field has \r\n too in them which is causing the line to break into two or more lines. ... (3 Replies)
Discussion started by: mehimadri12
3 Replies

5. UNIX Desktop Questions & Answers

Xfce not displaying with correct resolution

I have frequently installed xfce on both linux and freebsd machines, but something thathappens frequently is that the resolution of the display is not detected correctly. For instance on a 22 inch screen, the display is still 800x600 pixels. Similar things happen for 20 inch displays. The... (0 Replies)
Discussion started by: figaro
0 Replies

6. Shell Programming and Scripting

Displaying Number with printf

I am trying to display a number with commas printf "%d\n" 323232 printf "%d\n" 1234567 I want the output to be: 323,232 1,234,567 I tried to change %d to other formats and could find the solution. any idea? (7 Replies)
Discussion started by: ynixon
7 Replies

7. UNIX for Dummies Questions & Answers

Displaying Number with printf

I am trying to display a number with commas printf "%d\n" 323232 printf "%d\n" 1234567 I want the output to be: 323,232 1,234,567 I tried to change %d to other formats and could find the solution. any idea? (7 Replies)
Discussion started by: ynixon
7 Replies

8. UNIX for Dummies Questions & Answers

displaying mutliple fields on command line

This is probably the dumbest question you guys can get, but I'm trying, as a complete noob, to display the unix calendar for all the months without Saturday and Sunday showing. How can I remove those fields without having to type all the fields in individually such as: cal -y | awk '{print $2,... (3 Replies)
Discussion started by: Trellot
3 Replies

9. UNIX for Dummies Questions & Answers

awk: redrect printf to file and sort

{ printf "%s %6.2f\n", UserName, pay > payroll_report | sort -nk2 payroll_report; } this is what I have but it doesnt write the payroll_report file and gives a syntax error for the pipe...help?? (2 Replies)
Discussion started by: knc9233
2 Replies

10. Programming

Displaying fields in wtmp file?

Anyone have any idea on how to display the fields for each record stored in the wtmp file using C? Am I correct in thinking that the info stored in wtmp is in binary and that utmpx will be of some help? Being a beginner, I can come up with bits and pieces of what I might need in order to do the... (1 Reply)
Discussion started by: eclapton1
1 Replies
Login or Register to Ask a Question