Hi,
I want to create a file from a shell script. the data for the file will come from variables. that is the file format is like,
var1-value var2_value ...
that is, var1_value should be placed in first 10 spaces and var2_value should be placed in next 8 columns like that.
is there any idea to do like this?
Thanks in advance,
Raja.
use "touch" to create files, or "echo", like :
touch /opt/file-${var}-more.txt
echo "" > /opt/file-${var}-more.txt
vino
January 28, 2008, 7:32am
3
sysgate:
use "touch" to create files, or "echo", like :
touch /opt/file-${var}-more.txt
echo "" > /opt/file-${var}-more.txt
Or simply
> /opt/file-${var}-more.txt
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.
kittywu:
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.
Ya this is working good. tnk very much frnds.