bash - concatenation of two lines using awk -
i have file each row having 74 columns. have been trying combine these lines if first , second column matches. file looks below.
check_in|2000000000|ms|xxxx|xxxx|n|34|n|n|n|n|n|y|n|n|n|n|n|123456|aaaaaa|122333|||||||||||aaaaaa|bbbbbbb|ccccccc|||||||||||||||||||1000123|aaaa|n|qwerty||registered|registered|registered|unregistered|19-05-2015|video|edm||||||||||xxxxx check_in|2000000000|ms|xxxx|xxxx|n|34|n|y|n|n|n|n|n|n|n|n|n|345676|abcgdwejj|aaaaaaa||||||||||||||||||||||||nnnnnnn||||||||1000001|cccccc|n|qyuirt||registered|registered|registered|unregistered|19-05-2015|video|edm||||||||||xxxxx
i have used below script:
cat sample_file4.txt | awk -f "|" '{line=""; for(i = 3; <= nf ;i++) line = line $i"|"; table[$1"|"$2]=table[$1"|"$2]"|"line;} end { (key in table) print key "==>" table[key];}' > output9.txt
the record not appended first line.except key values, same line being repeated.like below
1.check_in|2000000000==>|ms|xxxx|xxxx|n|34|n|n|n|n|n|y|n|n|n|n|n|123456|aaaaaa|122333|||||||||||aaaaaa|bbbbbbb|ccccccc|||||||||||||||||||1000123|aaaa|n|qwerty||registered|registered|registered|unregistered|19-05-2015|video|edm||||||||||xxxxx 2.||ms|xxxx|xxxx|n|34|n|y|n|n|n|n|n|n|n|n|n|345676|abcgdwejj|aaaaaaa||||||||||||||||||||||||nnnnnnn||||||||1000001|cccccc|n|qyuirt||registered|registered|registered|unregistered|19-05-2015|video|edm||||||||||xxxxx
please me them onto single line.
i write this:
awk ' begin {fs = ofs = "|"} { key = $1 subsep $2 } !(key in lines) {lines[key]=$0; next} {$1=$2=""; line=$0; sub(/^../, "", line); lines[key] = lines[key] fs line} end {for (key in lines) {print lines[key]}} ' file
Comments
Post a Comment