1

I have this table which is messed up

DB  Size_in_MB
foobar  11011.2
barfoo  4582.9
donkey  4220.8
shoryuken   555.9
hadouken    220.0
kong    214.8
super_mario_bros_p  211.1

there are unnecessary spaces between columns. I want to add | and adjust the spaces between columns. I tried sed 's/\t/|/g'and sed 's/\t/\t|\t/g' but did not work

DB  |   Size_in_MB
foobar  |   11011.2
barfoo  |   4582.9
donkey  |   4220.8
shoryuken   |   555.9
hadouken    |   220.0
kong    |   214.8
super_mario_bros_p  |   211.1

I want the table like this:

DB                  |  Size_in_MB
foobar              |  11011.2
barfoo              |  4582.9
donkey              |  4220.8
shoryuken           |  555.9
hadouken            |  220.0
kong                |  214.8
super_mario_bros_p  |  211.1
4

Try the command column as follows:

cat file | sed 's/\t/,|,/g' | column -s ',' -t
DB                  |  Size_in_MB
foobar              |  11011.2
barfoo              |  4582.9
donkey              |  4220.8
shoryuken           |  555.9
hadouken            |  220.0
kong                |  214.8
super_mario_bros_p  |  211.1
  • thank you but this is still doesn't work. the columns are not adjusted! – Suzie Oct 7 '18 at 12:26
  • Hi @Suzie I just ran the command and the results as listed in my answer. Run the command on your original table! – user88036 Oct 7 '18 at 12:28
  • @Goro: also ran the command but did not work for me either. For me sed 's/\s\+/,|,/g' did the trick. – Thomas Oct 7 '18 at 12:33
  • 1
    Ah Ok my bad, it worked I was doing it on the second table. Thank you for help! – Suzie Oct 7 '18 at 12:34

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.