Created
April 18, 2020 19:14
-
-
Save okhlybov/ed3a6e291c10bf34deb0f2796dd4ff5d to your computer and use it in GitHub Desktop.
Ruby shell filter to sort space/newline delimited strings based on the floating point values extracted from the strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Scan space or newline delimited string list read from standard input for | |
# floating point values and sort it based on to the numbers found | |
def s2fp(s) ((s =~ /[-+]?[0-9]*\.?[0-9]+(e[-+]?[0-9]+)?/i).nil? ? 0 : $&).to_f end | |
puts ARGF.readlines.collect{|s| s.split}.flatten.sort{|a,b| s2fp(a) <=> s2fp(b)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment