lundi 8 décembre 2014

How to sort a content of a text file using a shell script?


I have 565075 entries which needs to be sorted. A sample script which will sort entries for such huge input will help me.



fap0089-josh.baker
fap00233-adrian.edwards
fap00293-bob.boyle
fap00293-bob.jones
fap002-brian.lopez
fap00293-colby.morris
fap00293-cole.mitchell
psf0354-SKOWALSKI
psf0354-SLEE
psf0382-SLOWE
psf0391-SNOMURA
psf0354-SPATEL
psf0364-SRICHARDS
psf0354-SSEIBERT
psf0354-SSIRAH
bsi0004-STRAN
bsi0894-STURBIC
unit054-SUNDERWOOD
user1
user2


Here, the data is of the format -


bsi, fap, unit etc are 'app' the numeric following the app name is the 'env' the name after the hypen is the 'user'


There might also be other values not of the format given above. e.g user1,user2


I need the data to be sorted in the following format


Sample output


NOTE : If 'app' value is fap,bsi etc, it should list all the unique environments in the 'env' column. e.g: the value of env is 5 for app name 'fap' as the number of unique env for fap is 5.


Total count should give the number of entries under the particular app. e.g: fap = 6, bsi = 2


The entries not falling under any app (not of the format '-'), e.g: user1, user2 should be put under the separate count list named 'non-app'. Here, the non-app count is 2.



Aucun commentaire:

Enregistrer un commentaire