How remove duplicated lines¶
Using awk¶
Sometimes lines are duplicated in your text file. You can easily remove these duplicates using awk
By adding the -i inplace flag, the original file is modified directly.
To remove duplicate lines based on a specific column, such as the second column, replace !seen[$0]++ to !seen[$2]++.
Using sort¶
You can use sort to remove duplicates. The following code sorts the file and selects unique values based on the second column.
The flags used are:
-u: prints only unique lines.-t: specifies the delimiter (in this case, a space).-k: specifies the column for sorting. For example:-k2: means sorting based on the second column-k1,3: means sorting from column 1 through column 3.-k1: means sorting from column 1 through the end.