There is the following text, where the first 5 lines of content are
1,111,111:13,443,253,456
2,222,222:13,211,222,122
1,111,111:13,643,543,544
3,333,333:12,341,243,123
2,222,222:12,123,123,123
After processing with the shell script, output in the following format:
[1111111]
13443253456
13643543544
[2222222]
13211222122
12123123123
[3333333]
12341243123
#!/bin/bashsort-n 1.txt |awk-f ': ' {print $} ' |uniq >id.txtfor ID in ' cat id.txt ' do echo ' [$id] ' awk-f ': ' $1== ' ' $id ' {print $} ' 1.txtdone
Analytical:
Sort-n using pure numeric sorting
Awk-f ': ' {print '} ' with ': ' Colon as delimiter, print first field (first part)
Uniq to repeat the line
>id.txt output redirected to ID.txt text
Awk-f ': ' $1== ' ' $id ' "{print $} ' 1.txt: Separated by a": "Colon, if the value of the first field equals the value of $id, the second field is printed.
Purely personal opinion, not in the right place, please point out
Shell: Working with text