The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 01-28-2008
KittyWu KittyWu is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 8
Hi,

the 'printf' primitive allows you to assign or display a formatted string.

It can be used this way:
#-----------------------------------------------------
typeset LP_FILE=${HOME}/tmp/test.txt

# Variables for test
typeset VAR1_VALUE='12345678'
typeset VAR2_VALUE='ABCDEF'

# Remove the target file if any
rm -f ${LP_FILE}

# Dump the data values to the file
printf "%-10s" ${VAR1_VALUE} >> ${LP_FILE}
printf "%-8s" ${VAR2_VALUE} >> ${LP_FILE}
# Add '\n' if you want a newline character: printf "%-8s\n"

# Display the results
echo "*** [BEGIN] '${LP_FILE}' file content"
cat ${LP_FILE}
echo "*** [END] '${LP_FILE}' file content"
#-----------------------------------------------------


Hope it helps,
C.