I have a script running which generates continuous output such as:
/AtherosC_92:f1:a7 BTHub4-NJ8S -82
/AtherosC_92:f1:a7 BTHub4-NJ8S -81
/95:8c:ed:6d:65:f5 Home245 -84
/AtherosC_92:f1:a7 BTHub4-NJ8S -78
/3d:cc:54:d1:4f:f6 BTWifi2 -82
/Apple_e5:e8:2d SKYBD80F -71
/Apple_e5:e8:2d SKYBD80F -71
/Apple_e5:e8:2d SKYBD80F -72
Each line is comprised of 3 sections (string, string, int as above). I need to assign each line a unique identifier based on the first string of each line, creating an output like this:
/1 AtherosC_92:f1:a7 BTHub4-NJ8S -82
/1 AtherosC_92:f1:a7 BTHub4-NJ8S -81
/2 95:8c:ed:6d:65:f5 Home245 -84
/1 AtherosC_92:f1:a7 BTHub4-NJ8S -78
/3 3d:cc:54:d1:4f:f6 BTWifi2 -82
/4 Apple_e5:e8:2d SKYBD80F -71
/4 Apple_e5:e8:2d SKYBD80F -71
/4 Apple_e5:e8:2d SKYBD80F -72
Any suggestions as to how his could be achieved?
Or in Perl:
A pure Bash solution:
The following is based on @rici's solution (thanks!):