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?

Was it helpful?

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top