Hi,
I have this sample file:
660312,MIKE , 138555.51
660312,MIKE , 219132.05
660312,MIKE , 246677.63
660312,MIKE , 268489.41 >>>>this record to be repeated
670182,JOHN , 155591.30
670182,JOHN , 246753.39
670182,JOHN , 279279.87
670182,JOHN , 303745.03
670182,JOHN , 408252.03 >>>>this record to be repeated
I am trying to repeat the last record where $1 is not matching with the next record.
awk -F, '{if(p!=$1){print $0; p=$1}print $0}'
But this is repeating the very first record after the condition is met.
Help will be appreciated.
On 19.07.2021 13:55, raj wrote:
Hi,
I have this sample file:
660312,MIKE , 138555.51
660312,MIKE , 219132.05
660312,MIKE , 246677.63
660312,MIKE , 268489.41 >>>>this record to be repeated
670182,JOHN , 155591.30
670182,JOHN , 246753.39
670182,JOHN , 279279.87
670182,JOHN , 303745.03
670182,JOHN , 408252.03 >>>>this record to be repeated
I am trying to repeat the last record where $1 is not matching with the next record.
awk -F, '{if(p!=$1){print $0; p=$1}print $0}'
But this is repeating the very first record after the condition is met.
Help will be appreciated.Maybe something like this...
awk -F, 'p && $1!=p {print d}; {p=$1; d=$0 }; 1; END{print d}'
Janis
Hi,
I have this sample file:
660312,MIKE , 138555.51
660312,MIKE , 219132.05
660312,MIKE , 246677.63
660312,MIKE , 268489.41 >>>>this record to be repeated
670182,JOHN , 155591.30
670182,JOHN , 246753.39
670182,JOHN , 279279.87
670182,JOHN , 303745.03
670182,JOHN , 408252.03 >>>>this record to be repeated
I am trying to repeat the last record where $1 is not matching with the next record.
awk -F, '{if(p!=$1){print $0; p=$1}print $0}'
But this is repeating the very first record after the condition is met.
Help will be appreciated.
Hi,
I have this sample file:
660312,MIKE , 138555.51
660312,MIKE , 219132.05
660312,MIKE , 246677.63
660312,MIKE , 268489.41 >>>>this record to be repeated
670182,JOHN , 155591.30
670182,JOHN , 246753.39
670182,JOHN , 279279.87
670182,JOHN , 303745.03
670182,JOHN , 408252.03 >>>>this record to be repeated
I am trying to repeat the last record where $1 is not matching with the next record.
awk -F, '{if(p!=$1){print $0; p=$1}print $0}'
But this is repeating the very first record after the condition is met.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (2 / 14) |
Uptime: | 73:20:17 |
Calls: | 6,489 |
Calls today: | 2 |
Files: | 12,096 |
Messages: | 5,275,836 |