The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
FTP is using shell scripts create ? for file a501420038 Shell Programming and Scripting 1 08-16-2007 11:39 AM
Read words from file and create new file using K-shell. bsrajirs Shell Programming and Scripting 4 06-01-2007 09:15 AM
.def file in HP-UX Shell scripting manu.vmr Shell Programming and Scripting 1 01-24-2007 09:17 AM
How to create file execution in KSH shell heru_90 Shell Programming and Scripting 4 06-23-2006 09:43 AM
file activity (open/closed) file descriptor info using KORN shell scripting Gary Dunn UNIX for Dummies Questions & Answers 3 06-07-2004 10:54 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-26-2008
Registered User
 

Join Date: Sep 2007
Posts: 30
Need to create file from shell scripting

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.
Reply With Quote
Forum Sponsor
  #2  
Old 01-28-2008
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,200
use "touch" to create files, or "echo", like :
Code:
touch /opt/file-${var}-more.txt
echo "" > /opt/file-${var}-more.txt
Reply With Quote
  #3  
Old 01-28-2008
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Quote:
Originally Posted by sysgate View Post
use "touch" to create files, or "echo", like :
Code:
touch /opt/file-${var}-more.txt
echo "" > /opt/file-${var}-more.txt
Or simply
Code:
> /opt/file-${var}-more.txt
Reply With Quote
  #4  
Old 01-28-2008
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.
Reply With Quote
  #5  
Old 01-28-2008
Registered User
 

Join Date: Sep 2007
Posts: 30
Quote:
Originally Posted by KittyWu View Post
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0