How to sort values that has different position of the fields in bash -


i discovered looking @ logs; commits git may have or not have name , last name; means if sort using -k, position of fields may not correct.

for example, if file commits various repository standard format have is

commit - name - surname - date - repo name

i sort them sort -k 4, them ordered date (that's need)/

problem is, committer name replaced generic name (not sure why, not managing repository); ends jumping 1 field, , date on 3rd position, not 4th.

this results in majority of commits ordered correctly, ones has date on 3rd position, end being @ bottom, don't have them ordered chronologically.

since cannot control repo throw @ me, there way tell sort, order date, without specify 1 field has date? or should use different sort?

can not check number of fields on line? i.e. counting last element instead of first?

granted sort may not have sufficient capabilities specify keys end of line, may have resort small awk script find the right sort key based on number of records in each line.

like;

# reorder fields date - reponame - commit - name - surname(optional) awk '{     if (nf==4) print $3, $4, $1, $2;      else print $4, $5, $1, $2, $3; }' file.log | sort -k1 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -