join all lines that have the same first column to the same line
问题 IE: File: 1234:abcd 1234:930 1234:999999 194:keee 194:284 194:222222 Result: 1234:abcd:930:999999 194:kee:284:222222 I have exhausted my brain to the best of my knowledge and can't come up with a way. Sorry to bother you guys! 回答1: $ awk -F: '$1==last {printf ":%s",$2; next} NR>1 {print "";} {last=$1; printf "%s",$0;} END{print "";}' file 1234:abcd:930:999999 194:keee:284:222222 How it works -F: This tells awk to use a : as the field separator. $1==last {printf ":%s",$2; next} If the first