I have 3 files ex- abc.txt, def.txt & xyz.txt. I've generate one shell script where I want to content of these 3 files should appear line wise like as below-
abc ---- 1 2 3 4 5 6 7
def ---- 3 5 7 9 11 13 15
xyz ---- 4 8 12 16 20 24 28
Also the content of the files should be like this manner & every value in parallel wise. Could you please help me to generate the shell script.
But in actual when i run script then it is showing like-
abc ---- 1 2 3 4 5 6 7
def ---- 3 5 7 9 11 13 15
xyz ---- 4 8 12 16 20 24 28
So I want to arrange like above content of the output. Where I used in the script for the above requirement-
for f in abc.txt def.txt xyz.txt; do (cat "${f}"; echo) >> output.txt; done
|awk '{printf "%-10s|%-10s|%-10s|%-10s|%-10s|%-10s|%-10s\n",$1,$2,$3,$4,$5,$6,$7} output.txt > final_output.txt
Is it good approach to generate the script
Best Answer
You can use the columns command
This will be close to your desired output but the numbers would not be right-justified
To right justify the numbers just pipe the output of your shell script to rev and columns command like this
rev
will reverse every linerev
will revert back the original line - giving you right aligned numbers.