Skip to content
Advertisement

Sed/awk: Aligning words in a file

I have a file with the following structure:

JavaScript

I want to add another item to the file, using sed or awk:

JavaScript

etc. So my next item looks like this:

JavaScript

The column values is jagged. How do I align my values to the left like for previous items? I can see 2 solutions here:

  1. To align the values while inserting them into the file.
  2. To insert the values into the file the way I did it and align them next.

The command

JavaScript

catches the properties and values I want to align, but I haven’t been able to align them properly, i.e.

JavaScript

It prints out the file, but it includes the description values and tags, cuts the values if they include spaces or dashes. It just a big mess.

I’ve tried more commands based on what I’ve found on Stack Overflow and some blogs, but nothing does what I need.

Note: Values of the description tags are not jagged- this is because I write them to the file in a separate way.

What is wrong with my commands? How do I achieve what I need?

Advertisement

Answer

When your file is without tabs, try this:

JavaScript

When this works, redirect the output to a tmpfile and move the tmpfile to file.txt.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement