I have a CSV file with only 2 columns (but lots of rows) and the occasional irregular row which always starts with an asterisk (*) character and may span more than two columns. Using just the Linux command line, the intended behavior is:
- If 3 or more consecutive data rows have the same value for column two, delete the middle rows. Start and end rows are retained.
- Retain the irregular rows that begin with an asterisk
For example, if I have a CSV with this content:
0,Apple
1,Apple
2,Apple
* Checkpoint
* Another checkpoint
3,Apple
4,Apple
5,Box
6,Box
7,Citrus
8,Box
9,Apple
10,Apple
11,Apple
12,Dove
13,Citrus
* Sudden checkpoint, * Leftover checkpoint note 1, * Leftover checkpoint note N
14,Citrus
15,Citrus
16,Citrus
17,Apple
18,Citrus
It should look like below after:
0,Apple
* Checkpoint
* Another checkpoint
4,Apple
5,Box
6,Box
7,Citrus
8,Box
9,Apple
11,Apple
12,Dove
13,Citrus
* Sudden checkpoint, * Leftover checkpoint note 1, * Leftover checkpoint note N
16,Citrus
17,Apple
18,Citrus
In the example above, lines 1 to 3, 10, and 14 to 15 were removed.
Thank you very much in advance for any answers.
Cheers