Sort command ignores the first row
-
21-12-2019 - |
Question
I'm having this problem with the sort where it is ignoring the first line. file1 is a bunch of data with the first column separated by a tab (\t)
My command:
sort -n file1 > file2
My file2:
10000356869 Music ,5330548481 ,Maroon 5
99858 Apps / Software / Website ,586481691394593 ,Best Vines
99859 Community ,427045773976651 ,Friends of the Blu 99860 Company ,83564764229 ,MAPCO
99861 Company ,90301409621 ,Charter Communicat
I believe that this is because the file was imported from a windows environment. It is the result of a MSSQL query. I was wondering if this is beacuse there is no '^' start of line character on the first line, or that it is not preceded by a '$' end of line. Could that be the cause? what is the solution?
Solution
Best to take out any leading tabs and spaces before you run the sort command. Try this:
sed -e 's/^[ \t]*//' | sort -n file1 > file2