I have a file with two columns. Each line in this file has a different size of words
awk \'$5=$9\' FS="#" OFS="\\t" file1**
Tomato#Vegetable
With Unix / Linux you can use column
to produce column output:
$ column -t -s '#' your_file
Tomato Vegetable
Orange Fruit
Cucumber Vegetable
Sweat Potato Fruit
To do it in awk
you can read the file twice to get the max field length for each column. Once you do that, you can fix the field width with sprintf
with the field width + pad value:
awk -F'#' -v pad=4 '
FNR==NR { # FNR==NR means first file
for (i=1;i<=NF;i++) # find the max width of each field
if(max[i]
Prints:
Tomato Vegetable
Orange Fruit
Cucumber Vegetable
Sweat Potato Fruit