We have requirement here to split file based on colum 3
on 3rd column we have 9 unique values based on this we need split into 2 files one
contain 4 another file contain remaining 5 (its based on no of unique values in 3 column if we have 20 unique values we will split into 10 & 10 )
and header should be added on both files
We will count the no of unique values with this cmd
awk -F’|’ ‘{print $3}’ inputfile.txt | sort | uniq
half of the count should in one file, remaining in another file
Input file
Header |Name | date
c | 125 | ER
de | 126 | ER
fr | 127 | ER
xe | 128 | ER
A | 123 | MR
b | 124 | MR
c | 125 | XR
de | 126 | YR
fr | 127 | ZR
xe | 128 | NR
A | 123 | BR
b | 124 | BR
c | 125 | CR
de | 126 | CR
fr | 127 | DR
xe | 128 | DR
A | 123 | ER
b | 124 | ER
Output file 1
c | 125 | ER
de | 126 | ER
fr | 127 | ER
xe | 128 | ER
A | 123 | ER
b | 124 | ER
fr | 127 | DR
xe | 128 | DR
c | 125 | CR
de | 126 | CR
A | 123 | BR
b | 124 | BR
output file 2
A | 123 | MR
b | 124 | MR
c | 125 | XR
de | 126 | YR
fr | 127 | ZR
xe | 128 | NR