sorting - Linux - numerical sort then overwrite file -
i have csv file general format
date, 2013.04.04, 2013.04.04, 2012.04.02, 2013.02.01, 2013.04.05, 2013.04.02,
a script run add data file not in date order. how can sort file date order (ignoring header) , overwrite existing file rather writing stdout
i have used awk
awk 'nr == 1; nr > 1 {print $0 | "sort -n"}' file > file_sorted mv file_sorted file
is there more effective way without creating additional file , moving?
you can following:
sort -n -o your_file your_file
-o
defines output file.
output
$ cat s date, 2013.04.04, 2013.04.04, 2012.04.02, 2013.02.01, 2013.04.05, 2013.04.02, $ sort -n -o s s $ cat s date, 2012.04.02, 2013.02.01, 2013.04.02, 2013.04.04, 2013.04.04, 2013.04.05,
Comments
Post a Comment