Reformat sql insert data:

('1', 'admin', '^/admin/$', null,'Admin Console', 0,'admin.dashboard.Admin', null),
('1-2',  'admin', '^/admin/aggregates/$', 1,'Host Aggregates', 0,'admin.aggregates.panel.Aggregates', null),
('1-2-1',  'admin', null, '1-2','Host Aggregates', 1,null, null),

to this:

('1',     'admin', '^/admin/$',            null,  'Admin Console',   0, 'admin.dashboard.Admin',             null),
('1-2',   'admin', '^/admin/aggregates/$', 1,     'Host Aggregates', 0, 'admin.aggregates.panel.Aggregates', null),
('1-2-1', 'admin', null,                   '1-2', 'Host Aggregates', 1, null,                                null),

Here is an alternative approach that just reads the csv, and formats it as a table. It uses powershell:

PS> import-csv myinput.csv | format-table

This doesn't change the CSV file itself. It just gives you a readable copy. If you want to put the readable copy in another file, do this:

PS> import-csv myinput.csv | format-table > mycopy.txt

Note: the real prompt isn't PS>. I just wrote it that way to save space.


Is there an ASCII character that will never appear in your data?  Perhaps @, % or ~?  If so, use that character as follows:

sed 's/, */,@/g' your_file | column -s'@' -t

The sed command separates your columns by @ characters, removing spaces between columns (but leaving the commas), like this:

('1',@'admin',@'^/admin/$',@null,@'Admin Console',@0,@'admin.dashboard.Admin',@null),@
('1-2',@'admin',@'^/admin/aggregates/$',@1,@'Host Aggregates',@0,@'admin.aggregates.panel.Aggregates',@null),@
('1-2-1',@'admin',@null,@'1-2',@'Host Aggregates',@1,@null,@null),@

The column command then separates the columns, using @ as the column separator (-s'@'), and formats the data as a table (-t).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.