1

How can I resolve the problem of the tables going to the right. I just want it to be shown under 1.

Here's my script with START added. The alignment has gone wonky now:

while IFS="," read f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12
do
 printf "START %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %5s" $f1 $f2 $f3 $f4 $f5 $f6 $f7 $f8 $f9 $f10 $f11 $f12; # ifet the student id
done < records.csv
echo " Press <enter> to return to main menu"
read null

enter image description here

4
  • What is inside records.csv. Can you post at least sample contents?
    – chaos
    Commented May 29, 2015 at 9:16
  • Possibly the first column, as detected by the script is empty. Please check the output when you change printf "%10s %10s %10s %5s %10s %5s %5s %5s %5s %10s %10s %10s" $f1 $f2 $f3 $f4 $f5 $f6 $f7 $f8 $f9 $f10 $f11 $f12; to printf "START %10s %10s %10s %5s %10s %5s %5s %5s %5s %10s %10s %10s" $f1 $f2 $f3 $f4 $f5 $f6 $f7 $f8 $f9 $f10 $f11 $f12; and see where the START appears.
    – Ned64
    Commented May 29, 2015 at 9:21
  • @Ned64 please look at up updated script above. i've put start in it. but still seems to go wonky
    – Unixmanix
    Commented May 29, 2015 at 10:25
  • What editor are you using to edit records.csv ? Run cat -vet records.csv are you seeing ^M$ at the end of any lines? As earlier requested, post a sample of your csv file as text.
    – fd0
    Commented May 29, 2015 at 10:55

2 Answers 2

1

You need to add a newline at the end of the printf statement, like so:

             printf "START %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %5s\n" $f1 $f2 $f3 $f4 $f5 $f6 $f7 $f8 $f9 $f10 $f11 $f12; # ifet the student id

(note the \n)

1

That is probably because, you give only 5 positions for 4th field, but it may have six characters like HARRY1 in your example:

printf "%10s %10s %10s %5s <...>
                       ^^^ 

However, there is nice prettifier in GNU/Linux column which automatically selects column width depending on incoming data:

$ cat test.csv
Harry,2
Ed,3
Mary,4
Looooooooongname,8

$ sed 's/,/ /' test.csv | column -t
Harry             2
Ed                3
Mary              4
Looooooooongname  8

$ sed 's/,/ /' test.csv | grep -v Looooooooongname | column -t
Harry  2
Ed     3
Mary   4

May be it is better choice for you?

1
  • thanks. I might try that out if this method doesn't work out.
    – Unixmanix
    Commented May 29, 2015 at 10:26

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.