sort command : -g versus -n flag - Ask Ubuntu


what's difference between using sort command -g , -n?

i have tried both flags ls -la , output identical.

the man-page says -g "compares according general numerical value" , -n "compares according string numerical value" ?

i don't mean there.

what "general numerical value" mean? "string numerical value" mean?

from sort info page, sort -g explained these

‘-g’ ‘--general-numeric-sort’ ‘--sort=general-numeric’      sort numerically, converting prefix of each line long      double-precision floating point number.  *note floating point::.      not report overflow, underflow, or conversion errors.  use      following collating sequence:          • lines not start numbers (all considered           equal).         • nans (“not number” values, in ieee floating point           arithmetic) in consistent machine-dependent order.         • minus infinity.         • finite numbers in ascending numeric order (with -0 , +0           equal).         • plus infinity.       use option if there no alternative; slower      ‘--numeric-sort’ (‘-n’) , can lose information when      converting floating point. 

sort -n natural sort expect

‘-n’ ‘--numeric-sort’ ‘--sort=numeric’      sort numerically.  number begins each line , consists of      optional blanks, optional ‘-’ sign, , 0 or more digits      possibly separated thousands separators, optionally followed      decimal-point character , 0 or more digits.  empty number      treated ‘0’.  ‘lc_numeric’ locale specifies      decimal-point character , thousands separator.  default      blank space or tab, ‘lc_ctype’ locale can change      this.       comparison exact; there no rounding error.       neither leading ‘+’ nor exponential notation recognized.       compare such strings numerically, use ‘--general-numeric-sort’      (‘-g’) option. 

check steeldriver's answer better explanation.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User