Assuming there are at least six more fields that you don't show preceding the 7th field with the data in the question, you may read the CSV file with a tool such as Miller (mlr
) to create a new location
field for your new values.
Assuming further you have headers in your CSV file (since you want to create a new location
field) and that the header for the 7th field is filepath
, then you could do the following:
mlr --csv put '$location = sub($filepath,".*\\","")' file
The sub()
function would remove all text before the last backslash in the filepath
field. The result of that operation is then assigned to the new location
field.
Testing:
$ cat file
A,B,C,D,E,F,filepath
1,2,3,4,5,6,OS:J:\output\Windows\System32\winevt\Logs\Security.evtx
1,2,3,4,5,6,OS:J:\output\Windows\System32\winevt\Logs\System.evtx
$ mlr --csv put '$location = sub($filepath,".*\\","")' file
A,B,C,D,E,F,filepath,location
1,2,3,4,5,6,OS:J:\output\Windows\System32\winevt\Logs\Security.evtx,Security.evtx
1,2,3,4,5,6,OS:J:\output\Windows\System32\winevt\Logs\System.evtx,System.evtx
$ mlr --c2p --barred put '$location = sub($filepath,".*\\","")' file
+---+---+---+---+---+---+---------------------------------------------------------+---------------+
| A | B | C | D | E | F | filepath | location |
+---+---+---+---+---+---+---------------------------------------------------------+---------------+
| 1 | 2 | 3 | 4 | 5 | 6 | OS:J:\output\Windows\System32\winevt\Logs\Security.evtx | Security.evtx |
| 1 | 2 | 3 | 4 | 5 | 6 | OS:J:\output\Windows\System32\winevt\Logs\System.evtx | System.evtx |
+---+---+---+---+---+---+---------------------------------------------------------+---------------+
Would you want to make the change in-place, then add the -I
option before --csv
on the command line.