I have a csv where I need to trim some text from a column probably using a regex. This is an example:
test.csv:
| Number | Text | Group |
|---|---|---|
| 1 | the id is G11 (sometimes) | A |
| 2 | the id is G12 | B |
| 3 | the id is G15 | C |
| 4 | the id is Z13 (always) | D |
I want to only grab the code value like (G11, G12, G15, Z13) from the Text column and replace the value so that I would get:
| Number | Text | Group |
|---|---|---|
| 1 | G11 | A |
| 2 | G12 | B |
| 3 | G15 | C |
| 4 | Z13 | D |
I have tried using forms of grep, awk, and sed but haven't got anything to work. I'm unfamiliar with bash, but essentially I want a new csv that looks like table 2.
These are my attempts, unsure how to only work on the Test column....
sed 's/([A-Z]\d{2}).*/([A-Z]\d{2})' test.csv > test2.csv