I'm trying to align output from a bash for
loop.
Currently, I'm getting output from my loop that looks like so:
Directory: /some/long/directory/path Remote: some-remote
Directory: /some/dir/path Remote: other-remote
Which I'm trying to align like so:
Directory: /some/long/directory/path Remote: some-remote
Directory: /some/dir/path Remote: other-remote
The current, basic loop that generates this output looks something like this:
for dir in $(find /some/path -type d -name .git); do
cd $dir
remote=$(git remote)
printf "Directory: $dir\tRemote: $remote\n
done
I've tried using:
column
(which formats each line separately, as it's a for loop)printf
(printf "Directory: %s Remote: %s\n" "$dir" "$remote"
)awk
(echo "Directory: $dir Remote: $remote" | awk '{printf ("%s-20s %s-20s %s-20s %s-20s",$1 $2 $3 $4)}'
)
Among many other variations of these commands.
I'm probably missing something basic (I tried my best at looking at other examples online and reading the man
pages), but I couldn't get it to work.
I'd really appreciate any pointers as to what I'm doing wrong.