[SOLVED] [Request] Bash How To Remove Rows In File Containing Text In Specific Column
by finalturismo from LinuxQuestions.org on (#4RPNG)
This is for my large hard drive wiper i am running at the moment
So i will be running a command that outputs text in the terminal
I will be appending these lines with >> smartlog.txt
i need to compare all rows containing a matching column 6 in the text file
For example if any columns contain a matching serial number in column 6
remove all rows but one containing that serial number. This way there will never be a duplicated hard drive in this text file.
If anyone can help me that would be GREATLY appreciated.
smartlog.txt
------1-----2--3----4--------------------5------------------6------------7
1 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475
2 /dev/sdc 42 100 38293 WDC_WD2500AAKX-753CA1 WD-WMAYW3745186 238475
3 /dev/sdd 39 100 33990 WDC_WD2500AAKX-75U6AA0 WD-WCC2F2030835 238475
4 /dev/sde 38 100 20462 WDC_WD3200AZKX-00D6NA0 WD-WMC1S0595773 305245
5 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475
6 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475
7 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475
8 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475


So i will be running a command that outputs text in the terminal
I will be appending these lines with >> smartlog.txt
i need to compare all rows containing a matching column 6 in the text file
For example if any columns contain a matching serial number in column 6
remove all rows but one containing that serial number. This way there will never be a duplicated hard drive in this text file.
If anyone can help me that would be GREATLY appreciated.
smartlog.txt
------1-----2--3----4--------------------5------------------6------------7
1 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475
2 /dev/sdc 42 100 38293 WDC_WD2500AAKX-753CA1 WD-WMAYW3745186 238475
3 /dev/sdd 39 100 33990 WDC_WD2500AAKX-75U6AA0 WD-WCC2F2030835 238475
4 /dev/sde 38 100 20462 WDC_WD3200AZKX-00D6NA0 WD-WMC1S0595773 305245
5 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475
6 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475
7 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475
8 /dev/sdb 40 100 47401 WDC_WD2500AAKX-753CA1 WD-WMAYW2921274 238475