Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort comma separated fields in row after = 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL

hello
I have the input file having lines:

dsafa=jadgd,afasfa,werww,bsdfasf
sdfas=sfjkhssdf,sdfisf,jiioww,sofjsss
sdfas=klsjfls,sfkhskjf,asafja,zxfssf
safas=oaiudaj,adasdfj,asfkjs,akjdhjkd
zsfda=hhdsdfs,cssfs,aodkoa,lsjdfssf

how sort in each line fields on the right side of the = (the comma separated ones) - so for example first two lines would be on output:

dsafa=afasfa,bsdfasf,jadgd,werww
sdfas=jiioww,sdfisf,sfjkhssdf,sofjsss

 
Hi

Personally I prefer Perl in cases like this :
Code:
perl -nlaF= -e '[b]print[/b][navy]$F[/navy][teal][[/teal][purple]0[/purple][teal]],[/teal][i][green]"="[/green][/i][teal],[/teal][b]join[/b][i][green]","[/green][/i][teal],[/teal][b]sort split[/b][i][green]","[/green][/i][teal],[/teal][navy]$F[/navy][teal][[/teal][purple]1[/purple][teal]][/teal]' /input/file


Feherke.
feherke.ga
 
Wouldn't this do it?

Code:
sort -t = -k 2 /path/to/input.day
 
Oh, gotcha. I thought it was sort rows by the fields after the '='. Much different.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top