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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

splitting up a list

Status
Not open for further replies.

jonnyc2

Programmer
Apr 4, 2006
7
GB
Hi

I have a list like this:

8 ./bk118/bk118_1220/work/fred/maya/data
8 ./sf118/sf118_1325/work/fred/maya/data
85876 ./tn125/tn125_1010/work/barney/maya/data
8 ./tn125/tn125_1020/work/barney/maya/data
4 ./tn125/tn125_1040/work/barney/maya/data
37468 ./rt117/rt117_1090/work/wilma/maya/data
4 ./ff038/ff038_1070/work/wilma/maya/data
4 ./sp127/sp127_1030/work/wilma/maya/data

and want it to look like this:

8 ./bk118/bk118_1220/work/fred/maya/data
8 ./sf118/sf118_1325/work/fred/maya/data

85876 ./tn125/tn125_1010/work/barney/maya/data
8 ./tn125/tn125_1020/work/barney/maya/data
4 ./tn125/tn125_1040/work/barney/maya/data

37468 ./rt117/rt117_1090/work/wilma/maya/data
4 ./ff038/ff038_1070/work/wilma/maya/data
4 ./sp127/sp127_1030/work/wilma/maya/data

so add a blank line whenever the username changes.

any ideas?

J
 
A starting point:
awk -F/ 'NR>1 && $5!=u{printf "\n"}{u=$5;print}' /path/to/list

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
[tt]awk -F/ 'NR>1 && $5!=prev {print ""}{print;prev=$5}' inputfile[/tt]

Annihilannic.
 
thanks guys thats awesome!

a couple of other things I'm trying to do if you have a moment:

print the username at the start of each block and the total of the first column. eg.

fred 16
8 ./bk118/bk118_1220/work/fred/maya/data
8 ./sf118/sf118_1325/work/fred/maya/data

barney 85888
85876 ./tn125/tn125_1010/work/barney/maya/data
8 ./tn125/tn125_1020/work/barney/maya/data
4 ./tn125/tn125_1040/work/barney/maya/data
 
nawk -f johnny.awk inputFile

johnny.awk:
Code:
BEGIN {
  SEPpath="/"
  FLDuser="5"
}
{
   split($2, u, SEPpath)
   userList[u[FLDuser]] = (u[FLDuser] in userList) ? userList[u[FLDuser]] SUBSEP $0 : $0
   userTotal[u[FLDuser]] += $1
}

END {
  for (i in userTotal) {
    printf("%s %d\n", i, userTotal[i])
    gsub(SUBSEP, "\n", userList[i])
    printf("%s\n\n", userList[i])
  }
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top