0

In Linux in Bash in a for loop i do:

... ; do echo "$i --> $i-new" ; ...

The output is than something like this:

file1  -->  file1-new
file2  -->  file2-new
...
file9  -->  file9-new
file10  -->  file10-new
file11  -->  file11-new

how to become an output like this:

file1   -->   file1-new
file2   -->   file2-new
...
file9   -->   file9-new
file10  -->  file10-new
file11  -->  file11-new

?

1 Answer 1

1
for i in file{1..11}; do
    printf '%s\t-->\t%s\n' "${i}" "${i}-new"
done | column -t -d -s$'\t' -R3
  • printf '%s\t-->\t%s\n' "${i}" "${i}-new": prints three tab-separated columns for, respectively, fileN, --> and fileN-new

In column:

  • -t: create a table, with columns separated by two spaces
  • -d: don't print the table's header
  • -s$'\t': assume the input items are tab-separated
  • -R3: align the contents of column #3 to the right
% for i in file{1..11}; do printf '%s\t-->\t%s\n' "${i}" "${i}-new"; done | column -t -d -s$'\t' -R3
file1   -->   file1-new
file2   -->   file2-new
file3   -->   file3-new
file4   -->   file4-new
file5   -->   file5-new
file6   -->   file6-new
file7   -->   file7-new
file8   -->   file8-new
file9   -->   file9-new
file10  -->  file10-new
file11  -->  file11-new

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.