I have over 150 CSV files with inconsistent columns on MAC (Unix) e.g:
Sheet A
ID | Col | mobile | secondary mobile | Name | |
---|---|---|---|---|---|
v | v | v | v | v | v |
v | v | v | v | v | v |
Sheet B
ID | Col | Col | Col | Col | Col |
---|---|---|---|---|---|
v | v | v | v | v | v |
v | v | v | v | v | v |
Sheet C
col | MOBILE | name | Col | col | |
---|---|---|---|---|---|
v | v | v | v | v | v |
v | v | v | v | v | v |
Sheet D
ID | col | col | col | Mobile | col |
---|---|---|---|---|---|
v | v | v | v | v | v |
v | v | v | v | v | v |
I need to DERIVE a new-sheet from each of the aformentioned sheet with the following columns (in case any exists)
ID, NAME, EMAIL, MOBILE, SECONDARY_MOBILE
Then I will combine the newly derived sheets into one sheet using CAT. So that I can upload the data into Oracle DB.
So, When it comes to SHEET D, I suppose, the derived sheet should be
ID | NAME | MOBILE | SECONDARY_MOBILE | |
---|---|---|---|---|
V | ||||
V |
I hope it is clear. Thanks in advance.
csvcut
ormlr
(Miller) that can work with column names directly, or loop over the header line to find the indices of the desired columns. See for example How to print certain columns by name? – steeldriver Aug 07 '21 at 16:51name
or can it also beName
? How are fields defined? By commas? Spaces? Tabs? – terdon Aug 07 '21 at 16:53head file.csv
on the files. You are asking for a text-based solution, so we need a text file to work with. We need to know how your columns are defined, if there are IDs, how we can know if a column is present or not etc. – terdon Aug 07 '21 at 21:12