Click here to Skip to main content
16,007,885 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I hav a file of some key value pairs need to sort,values r


1306014503350001,0.7167574
1371031512360001,0.4335363
1371054509380001,2.3803377
1671046105520001,1.4315698
1810041005700002,0.030490799
1903034506620003,0.44315025
3171011804580003,0.72508544
3171015707400001,0.82567614
3171016009600004,0.44152263
3171077112400014,0.32794788
3171080502520003,0.46428326
3173010903500003,0.40578112
3173014203420002,0.67425823
3173015811550002,2.4808035
3174095204390002,0.9443519
3175036405300002,2.0835547
3175044211580002,0.3450352


need to sort based on values after comma(,).According to dat integer values should b sorted but o/p should b as it is in i/p file in the sense integers should b first
Posted
Updated 5-Oct-11 2:42am
v2
Comments
TorstenH. 5-Oct-11 8:41am    
and? How much of this have you already accomplished?
udayz999 5-Oct-11 8:56am    
First of all thanq fr respone,i m tryng but its nt working,if possible snd me the code
TorstenH. 5-Oct-11 9:00am    
naa, it's not working that way. This is typical homework. Post your code and we will be delighted to help you. Put we don't provide ready-to-go solutions.

Use the command prompt as follows :
c:\> sort input.txt > output.txt
 
Share this answer
 
Comments
RedDk 5-Oct-11 12:37pm    
I like yours better ... do this instead.
Open Excel, click-on the half-inch diameter ribbon icon-thingy, click-on new/ blank-workbook create, mouse on down to the tabs at the bottom of the spreadsheet, delete sheet3 and sheet2. Then click-on Data tab back above, select "From text" button, mouse to the directory containing your textfile with the above data in it, choose open and when the dialog pops up choose delimited. Then choose, in the next panel "comma" delimiter.

Eventally choose "A1 ...ok".

And now you've got two columns of data.

Select all the data using your mouse, then, back under the "home" tab, choose "sort filter/custom filter" and when the dialog pops up, choose the column you want to sort on.

Once the list is appropriately plied, save the file as .txt.

Or whatever looks good or you find more useful than .txt.

[edit]

Close Excel.

[edit]
 
Share this answer
 
v2
Java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;



public class validate2 
{
	private Map<double,> dataMap = null;
	
	public static void main(String[] args) throws IOException {
		
		String dataFileName = "E://abc1.txt";
		Validate validate = new Validate();
		validate.initializeData(dataFileName);
		validate.printData();
		}
	public String getValue(Double key) 
	{
		String value = null;
		Long longValue = null;
	
		if ((longValue=dataMap.get(key)) == null) 
		{
			value = "value is null";
			
		} else {
			value = longValue.toString();
			
		}
		return value;
	}
}


================================================================================
**this is my work, which is wrong,at first i need to get the integer values & later float values**

306014503350001,0.7167574
1371031512360001,0.4335363
1371054509380001,2.3803377
1671046105520001,1.4315698

o/p should b in above format aftr sorting
===============================================================================
 
Share this answer
 
v2
Comments
TorstenH. 5-Oct-11 9:35am    
what does your class Validate do?

You don't need the HashMap there, as the file is inserted directly to your object Validate. so the field dataMap will always be empty.

1. Make sure you read the values correctly (check the HashMap by debugging the read-mechanism you're using).
2. sort the values.
3. return the values to the desired output (probably some System.out.println("").

Take time and do one step after the other.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900