linux - Issue with unix sort -
this more of doubt question.
so have input file this:
$ cat test class||sw sw-explr bot|results|id,23,0a522b36-556f-4116-b485-adcf132b6cad,20130325,/html/body/div/div[3]/div[2]/div[2]/div[3]/div/div/div/div/div/div[2]/div/div/ul/li[4]/div/img class||sw sw-explr bot|results|id,40,30cefa2c-6ebf-485e-b49c-3a612fe3fd73,20130323,/html/body/div/div[3]/div[2]/div[3]/div[3]/div/div/div/div/div[3]/div/div/ul/li[8]/div/img class||sw sw-explr bot|results|id,3,72805487-72c3-4173-947f-e5abed6ea1e4,20130324,/html/body/div/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div/div[3]/div/div/div[2]/ul/li[20]/div/img
kind of defining element in html page. comma separated 5 columns can considered.
i want sort
file respect second column, i.e. columns having 23,40,3.
i not sure why unix
sort
isn't working.
these queries tried, surprisingly none gave me desired result.
cat test | sort -nt',' -k2 cat test | sort -n -t, -k2 cat test | sort -n -t$',' -k2 cat test | sort -t"," -k2 cat test | sort -n -k2
is there sort
don't know?
this didn't cause me problem separated columns, sorted, joined again. why did not sort
work??
nb:- if remove $3 of file , sort, works fine!
this line should work you:
sort -t, -n -k2,2 test
- you don't need
cat test|sort
,sort file
- the default end pos of
-k
end of line. ifsort -k2
means sort 2nd field till end of line. in fact need sort exact 2nd field. , explains why sort worked if removed 3rd col.
if test example:
kent$ sort -t, -n -k2,2 file class||sw sw-explr bot|results|id,3,72805487-72c3-4173-947f-e5abed6ea1e4,20130324,/html/body/div/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div/div[3]/div/div/div[2]/ul/li[20]/div/img class||sw sw-explr bot|results|id,23,0a522b36-556f-4116-b485-adcf132b6cad,20130325,/html/body/div/div[3]/div[2]/div[2]/div[3]/div/div/div/div/div/div[2]/div/div/ul/li[4]/div/img class||sw sw-explr bot|results|id,40,30cefa2c-6ebf-485e-b49c-3a612fe3fd73,20130323,/html/body/div/div[3]/div[2]/div[3]/div[3]/div/div/div/div/div[3]/div/div/ul/li[8]/div/img
Comments
Post a Comment