Artificial intelligent assistant

Rolling up Multiple Rows into a Single Row How can I rollup multiple rows from a csv file into 1 row ? I have tried working out the query in SQL and it works but I am not sure how can I achieve the same in Linux. This is how my current file looks : swainb02,Ben Swain,1015 swainb02,Ben Swain,1016 swainb02,Ben Swain,1018 swainb02,Ben Swain,1020 shaiks21,Sarah Shaikh,0073 shaiks21,Sarah Shaikh,0080 shaiks21,Sarah Shaikh,0082 There are multiple users with access to multiple area codes. What I am looking for is a simpler version of this file for better readability. Desired Output : swainb02,Ben Swain,1015,1016,1018,1020 shaiks21,Sarah Shaikh,0073,0080,0082 Any idea how can this be worked out ? Thanks

Assuming your input is grouped by the key values as shown in your question (if not just sort the input first) then using any awk in any shell on every Unix box and using almost no memory no matter how large your input file is:


$ cat tst.awk
BEGIN { FS=OFS="," }
{ curr = $1 OFS $2 }
curr != prev {
printf "%s%s", ors, curr
prev = curr
ors = ORS
}
{ printf "%s%s", OFS, $3 }
END { printf ors }



$ awk -f tst.awk file
swainb02,Ben Swain,1015,1016,1018,1020
shaiks21,Sarah Shaikh,0073,0080,0082

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 15c965e0f9b78b7b57f131cb86c3b8ab