Issue
I have a question regarding Unix and shell. So my input file looks as follows:
path/filename ... username
path/filename2 ... username2
path/filename ... username2
...
and my desired goal, using ideally awk or sed, is to output something like:
filename username,username2
filename2 username2
so basically output one line for each unique file and print there all usernames, who opened them, all these values are stored in the input file so I'm just looking for an easiest way how parse them and do so.
Thanks in advance
Solution
Something like this. First prepare the basename, then append usernames, finally print the array.
% awk '{sub(/.*\//, "", $1)
arr[$1] != "" ? arr[$1]=arr[$1]","$NF : arr[$1]=$NF}
END{for(i in arr){print i,arr[i]}}' file
filename username,username2
filename2 username2
Answered By - Andre Wildberg Answer Checked By - David Marino (WPSolving Volunteer)