I need to create a simple fixed width text file in KShell. My current attempt using printf to pad the string isn't working out very well. What's the shortest, cleanest way to create a fixed width string in shell?
+1
A:
KSH compresses several spaces into one when it parses certain inputs. So to achieve what you want, you must write the formatted string directly to a file without passing it through any variables. Use printf
to format everything in one go and redirect to the file:
printf "%-10s%-5s%-20s\n" $str1 $str2 $str3 >> file
Aaron Digulla
2009-11-16 13:51:39
+1
A:
As I stated in my answer to that question, you need to put quotes around your variables.
TEXT=`padSpaces "TEST" 10`
TEXT="${TEXT}A"
echo ${TEXT}
TEST A
echo "${TEXT}"
TEST A
Dennis Williamson
2009-11-16 16:17:49
Thanks, I've got that now.
C. Ross
2009-11-16 16:53:29