Answers for "sort command linux"

0

sort in linux bash

your list of files in a paticluer folder :
cluster_data.txt
cluster_49.txt
cluster_39.txt
cluster_44.txt

ls -ltr cluster_*.txt | grep -v cluster_data.txt  # will do the sort
	OR
ls -ltr cluster_*.txt | grep -v cluster_data.txt | sort -t _ -k 2 -g
							^ avoid this file
-t separator
-k key/column
-g general numeric sort

https://stackoverflow.com/questions/17061948/sorting-strings-with-numbers-in-bash
Posted by: Guest on September-29-2021
0

sort command linux

ls -l | sort -n5 # sort column 5 ( -n sort numarically)
ls -l | sort -k9 # sort column 9 ( -k non numeric )
ls -l | sort -nk5 # sort columnt 2 # this is the best way 

sort according to columne 2 and 9
ls -l | sort -nk2,9

sort 1st colunm and then 2nd column depend on 1st column
cat energy.txt | sort -nk1,1 -nk2,2

sort -u # remove duplicates

your file set is like : 
md_5.mdcrd
md_14.mdcrd
md_20.mdcrd

ls -ltr md_*.mdcrd | awk '{ split($9,a,"."); split(a[1],b,"_"); print b[2]}' | sort -nk1

will give you 
5
14
20


https://www.tecmint.com/sort-command-linux/
Posted by: Guest on October-29-2021

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language