Reputation: 1316
Attempting to print out a list of values from 2 different variables that are aligned correctly.
foreach finalList ($correctList $wrongList)
printf "%20s%s\n" $finalList
end
This prints them out an they are aligned, but it's one after another. How would I have it go through each item in each list and THEN go to a new line?
I want them to eventually appear like this:
Correct Incorrect
Good1 Bad1
Good2 Bad2
Good3 Bad3
Good comes from correctList Bad comes from wrongList
Getting rid of \n makes it Like this:
Good1 Bad1 Good2 Bad2
I just want 2 columns.
Upvotes: 2
Views: 18346
Reputation: 2883
I believe the pr(1) command with the -m option will help do what you want. Look at its man page to eliminate the header/trailer options and set the column widths.
Also, I recommend you not use the C-Shell for scripting; you'll find the sh-syntax shells (sh, bash, ksh, etc) are more consistent and much easier to debug.
Upvotes: 0
Reputation: 109022
You can iterate over both lists at the same time like this:
# Get the max index of the smallest list
set maxIndex = $#correctList
if ( $#wrongList < $#correctList ) then
set maxIndex = $#wrongList
endif
set index = 1
while ($index <= $maxIndex)
printf "%-20s %s\n" "$correctList[$index]" "$wrongList[$index]"
@ index++
end
Upvotes: 5