sort data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort data
# 8  
Old 09-15-2005
It worked!! but... there is always a but.

The code worked just fine! Thanks, you are a life-saver!! But then another problem occured. After redirecting the sorted data into a new file "datanew.dat", it was to be plotted using gnuplot. gnuplot is invoked using the same script in which the "sorting" code is implemented. It seems like the sorting process and data redirect finishes after gnuplot is initiated. Which then results in a gnuplot request of a file that is not yet created. I'm sure there is away to do this but my familiarity with ruby is rather slim. So once again I turn to you for help.

Can I somehow stall the initiation of gnuplot until the sorting and redirecting (resulting in datanew.dat) are finished?

the active parts of the script are shown below:

# I want this process to end before continuing to the next (invoking GNUplot)
ruby -00ne'puts split("\n").sort_by{|x|x[/\s\S+/].to_f};puts' data.dat > datanew.dat


#Invoking gnuplot with input file gnu.ini
gnuplot gnu.ini

"gnu.ini" contains all plot properties such as labels, gridsize, ticlevel etc, including the command to plot datanew.dat.

regards

bjorb
# 9  
Old 09-15-2005
Ygor or vlad: please help us out here! This seems more like a shell issue than a Ruby one.

bjorb, I'm glad you're using Ruby! You're the first person on this forum who has said that he was able to use my Ruby code.
# 10  
Old 09-15-2005
When a problem can be solved so elegantly with your code solution, I would be stupid not to use it Smilie . Once again, thanks futurelet! I must admit, I do not understand the code presented but I will make an effort to do so.
# 11  
Old 09-15-2005
What is your shell's command to make the script pause for x seconds?
Try inserting that after the Ruby line.

An explanation of the code:
ruby -00ne'puts split("\n").sort_by{|x|x[/\s\S+/].to_f};puts' file

Code:
Switches:
  00     Make the record-separator an empty line. (In Awk, RS="".)
  n      Automatically read each record of the file, as Awk does.
  e      Program follows.

Program:
  split("\n)
         Short for $_.split("\n").  $_ is the record just read ($0 in Awk).
         The array created by split is then sorted by sort_by, which
         is a built-in implementation of the "Schwartzian Transform"
         that Perlers drool about.
{ |x| x[/\s\S+/].to_f }
         This is the code-block passed to sort_by. x is the parameter;
         an element of the array.
         x[ /\s\S+/ ]  This means "give me the part of the string x
         that is matched by the regular expression."   \s is whitespace;
         \S is non-whitespace.  This grabs the 2nd field.
         The matching substring is then converted to a floating-point
         number by  .to_f
         So sort_by sorts the array on the 2nd field, with each item
         treated as a float, not a string.
         puts  simply prints with appended linefeed; it cleverly prints
         each item of an array on a separate line.

# 12  
Old 09-15-2005
it seems starnge why gnuplot starts on the 'incomplete' data produced by ruby.
is ruby invoked synchronously or Asynchronously?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to sort out data

Hello All, I have one file with multiple lines records like as below.. I need to extract only BFG and corresponding BSG record/line. for evry BFG there is one BSG record is there as mentioned in BOLD and so on... BFG BR 00001 20140724 000 000 ? ? BLG UVR QPR 01 380 ? ? 999 0 0 0 ? BLC... (2 Replies)
Discussion started by: Riverstone
2 Replies

2. Shell Programming and Scripting

Sort data As per first Column

hI I have file A NSU30504 5 6 G 6 NSU3050B T 7 9 J NSU30506 T I 8 9 NSU3050C H J K L Output: NSU3050B T 7 9 J NSU3050C H J K L NSU30504 5 6 G 6 NSU30506 T I 8 9Video tutorial on how to use code tags in The UNIX and Linux Forums. (13 Replies)
Discussion started by: pareshkp
13 Replies

3. UNIX for Dummies Questions & Answers

sort data

Hi, I need to filter the output of a command and display certain data only. How can i do this ? My file contain: $ cat abc.txt <testcase title="AAA_100"> <testcase title="BBB_200"> <testcase title="CCC_300"> <testcase title="DDD"> ... (3 Replies)
Discussion started by: crazydude80
3 Replies

4. Shell Programming and Scripting

Sort Data by Group !

Hello, I have a file and i want to sort by third column and extract the three top lines of each group, it is determined by the second column (144, 89, 55, etc). Could you please help me with the appropiate awk shell script XLY-XLP 144 0.592772 XLY-XLE 144 0.798121 ... (3 Replies)
Discussion started by: csierra
3 Replies

5. Shell Programming and Scripting

Help needed to sort data

Hello All, Today i have been asking lots of question, hope to become good in scripting soon with all the wonderful advices i get. The question is i want to sort data a get uniq string from it. The code i am using to generate the output is:- check_sun() { for i in $SUN_PLATFORM do $ECHO... (0 Replies)
Discussion started by: asirohi
0 Replies

6. Shell Programming and Scripting

Trying to sort data

Im trying to sort all this data. I need to get a list out of the data (websites) and just list them out can anyone point me in the right direction. Im working with dans guardian. 2009.6.10 6:26:50 - 192.168.42.200... (5 Replies)
Discussion started by: darknirvana
5 Replies

7. UNIX for Advanced & Expert Users

sort out the required data

Hi All, I have a file 1.txt which has the duplicate dns entries as shown: Name: 000f9fbc6738.net.in|Addresses: 10.241.66.169, 10.84.2.222,212.241.66.170 Name: 001371e8ed3e.net.in|Addresses: 10.241.65.153, 10.84.1.101 Name: 00e06f5bd42a.net.in|Addresses: 10.72.19.218,... (6 Replies)
Discussion started by: imas
6 Replies

8. Shell Programming and Scripting

Sort complex data

Hi, Can someone here help sorting the following data in numeric order? INPUT: FIRST abc(3) def(13) fgh(1) ijk(6) abc(2) SECOND dfe(10) abc(4) hij(19) tlm(1) hij(1) hub(10) abc(1) fed(3) OTHERS hij(10) mok(4) bub(19) hij(1) abc(2) abc(15) abc(1) hij(3) OUTPUT: FIRST def(13) ijk(6)... (12 Replies)
Discussion started by: need_help
12 Replies

9. Shell Programming and Scripting

sort data in different columns

Hello all: i have list with the following format Id Name Iid Value 0x4440001 customerCode 44077 0x11d2a PrimaryAddress 57.217.41.201 0x129fa ... (15 Replies)
Discussion started by: mogabr
15 Replies

10. Shell Programming and Scripting

Script to sort data

Hi All, I have a .csv file with 3 columns called nLats, nLongs, and fRes. in following format : "nLats","nLongs","fRes" 0,0,-1 0,1,-1 0,2,-1 0,3,-1 0,4,-1 ......... ......... 0,143,-1 nLats increments at nLongs=143 1,0, -1 1,1, -1 .......... .......... 1,143,-1... (1 Reply)
Discussion started by: wizardy_maximus
1 Replies
Login or Register to Ask a Question