The file file2 content is as follows:
0 Qwert
1 ASDFGHJK
2 ASDJKL
2 zxcvbn
3 Dfghjkll
4 22222
4 TYUIOP
4 BNM
Make the first column equal to one row, not the first column, that is, the following format:
22222;tyuiop;bnm
Qwert
Asdfghjk
Asdjkl;zxcvbn
Dfghjkll
The first method of solution
Problem Solving Ideas:
awk ' {if (a[$1]) {a[$1]=a[$1] ";" $2}else{a[$1]=$2}}end{for (i in a) print A[i]} ' file2
File2
0 Qwert
1 ASDFGHJK
2 ASDJKL
2 zxcvbn
3 Dfghjkll
4 22222
4 TYUIOP
4 BNM
First line if (A[0]) because a[0] does not have any value, so the output is directly else a[0]= Qwert
The second line if (a[1]) because a[1] does not have any value, so the output is directly else a[1]= ASDFGHJK
The third line if (a[2]) because a[2] does not have any value, so the output is directly else a[2]= ASDJKL
Line four if (a[2]) because a[2]= ASDJKL, meet the conditions, execute a[$1]=a[$1] ";" $----> a[2]=a[2] ";" $--->a[2]=asdjkl;zxcvbn
Line five if (a[3]) because a[3] does not have any value, so direct output else a[3]= dfghjkll
Line six if (A[4]) because A[4] does not have any value, so direct output else a[4]= 22222
Line seventh if (A[4]) because a[4]= 22222, meet the conditions, execute a[$1]=a[$1] ";" $----> a[4]=a[4] ";" $--->A[4]=22222;TYUIOP
Line eighth if (A[4]) because a[4]= 22222;TYUIOP, meet the conditions, execute a[$1]=a[$1] ";" $----> a[4]=a[4] ";" $--->a[4]=22222;tyuiop;bnm
The final result after the entire file cycle is:
a[0]= Qwert
a[1]= ASDFGHJK
A[2]=asdjkl;zxcvbn
a[3]= Dfghjkll
A[4]=22222;tyuiop;bnm
End{for (i in a) print A[i]}
Use for to go to array a subscript 0 1 2 3 4
Then respectively print a[0] a[1] a[2] a[3] a[4]
(because the index of the extracted array is an irregular output, the result may be a random sort)
The second method of solution
Shell script, awk merging a column of issues.