Need help figuring out how to merge data from a file. I have a large txt file with some data that needs to be merged from separate lines into one line.
I can awk and tell me there is a difference on each line but can not figure out how to perform the desired merged output. There are some entries where three lines as in Eric or none as Steve, if there where all dups I could sort and cut | merge on next line.
awk '{i=$1 FS $2} !B[$0]++{A=A (A?",":x) $3; C=$4} END{for(i in A) print i,A,C}' FS=\| OFS=\| file
--
awk '
{
i=$1 FS $2 # Set index to $1 "|" $2
}
!B[$0]++ { # Only execute if line has not occurred before. Discard duplicate lines, using independent array B
A=A (A?",":x) $3 # Add $3 to the string if A is not empty, the prepend a comma else prepend nothing (x)
C=$4 # Add the fourth field to a entry with index i in separate array C
}
END {
for(i in A) print i,A,C # For all found indices where the entire line is no duplicate, print the index "|" concatenated field 3 "|" C
}
' FS=\| OFS=\| file