LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-28-2010, 09:36 PM   #1
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Rep: Reputation: 0
is there a way to make our data consecutive?


Dear All,

I indeed need your help for my research data file. I have a question about how to make our data consecutive.

For example I have data like:

id type-of-atoms energy

1 Si 45

3 O 23

5 Si 42

4 Si 12

2 H 10


how to change my data to :

id type-of-atoms energy

1 Si 45

2 H 10

3 O 23

4 Si 12

5 Si 42


thank you very much for all helps.

Mauludi
 
Old 02-28-2010, 09:52 PM   #2
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
You didn't mention what type of data file you have, but if it's text, the sort command should work.
 
Old 02-28-2010, 10:25 PM   #3
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Original Poster
Rep: Reputation: 0
yes it is a text file
 
Old 02-28-2010, 11:33 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by mauludi View Post
yes it is a text file
Ok.......did you try the sort command as suggested?
 
Old 03-01-2010, 12:55 AM   #5
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Original Poster
Rep: Reputation: 0
sorry, actualy example I mention above is not my real data, but the goal is the same, I want to have the first column consecutive..
after trying "sort command" I found part of my real data like below.
please see first column, it is not fully order. How to fix it?

1000 2 0.248762 0.551637 0.700014 13.5078 29.9539 38.0107 0.00290278 -104.335 2
1001 2 0.2245 0.526512 0.725539 12.1903 28.5896 39.3968 0.000248062 -104.665 2
1002 2 0.273159 0.574901 0.725091 14.8325 31.2171 39.3724 -0.0016636 -104.655 2
100 3 0.255067 0.246316 0.509907 13.8502 13.375 27.688 0.305618 -80.6206 3
1003 2 0.29817 0.50134 0.700065 16.1906 27.2227 38.0136 0.000511279 -104.64 2
1004 2 0.348057 0.550705 0.702942 18.8995 29.9033 38.1697 0.000560667 -104.646 2
1005 2 0.322922 0.524964 0.725336 17.5347 28.5055 39.3857 -0.00037471 -104.773 2
1006 2 0.374066 0.574454 0.727417 20.3118 31.1929 39.4988 6.43107e-06 -104.176 2
1007 2 0.396905 0.499235 0.701148 21.552 27.1085 38.0723 -0.00213138 -103.86 2
1008 2 0.447444 0.550564 0.702005 24.2962 29.8956 38.1189 0.00475884 -103.317 2
1009 2 0.423292 0.524987 0.724505 22.9848 28.5068 39.3406 0.000565073 -104.153 2
1010 2 0.473879 0.576283 0.725755 25.7316 31.2922 39.4085 0.00280028 -103.934 2
1011 2 1.00032 0.60085 0.702084 54.3172 32.6261 38.1232 0.000585666 -104.059 2
1012 2 0.0494911 0.650394 0.702936 2.68736 35.3164 38.1694 0.00263579 -103.903 2
1013 2 0.0248389 0.626711 0.726759 1.34875 34.0304 39.463 -0.000315563 -103.828 2
101 4 0.228359 0.224664 0.535099 12.3999 12.1992 29.0559 0.0586548 -97.838 4
 
Old 03-01-2010, 01:11 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Try the -n option for a numeric sort. "man sort" for all the options.
 
Old 03-01-2010, 01:47 AM   #7
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Original Poster
Rep: Reputation: 0
I found the same result
 
Old 03-01-2010, 07:31 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I put your data into a file and then ran "sort -n filename". It listed everything in numerical order based on the first column. 100, 101, 1000, 1001, 1002,....etc.

Please post the exact command you are using
 
Old 03-01-2010, 07:28 PM   #9
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Original Poster
Rep: Reputation: 0
ok, I know my mistake, I used sort keys. Now is okay.
thank you for your help.
 
Old 03-01-2010, 07:33 PM   #10
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Original Poster
Rep: Reputation: 0
sorry , I also wonder how "sort -n filename" command can change first column only where as it does not mention which column.
why not "sort -n -1 filename" ?. If I want to make second column consecutive rather than first column what should I write?

thank you very much for sharing your knowledge.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running X windows in WinXP through two consecutive SSH connections? rick2009 Linux - Networking 3 06-28-2009 04:16 PM
regular expression consecutive iamback Programming 4 01-12-2008 03:56 AM
consecutive rsync between three machines horacioemilio Linux - Newbie 2 01-05-2008 09:08 PM
consecutive 'write's or 'send's on a socket ananthbv Programming 2 09-26-2005 04:51 AM
Add consecutive numbers to a Chinese file tcma Linux - General 0 10-19-2004 04:25 PM


All times are GMT -5. The time now is 05:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration