Need to create file from shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to create file from shell scripting
# 1  
Old 01-26-2008
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.
# 2  
Old 01-28-2008
use "touch" to create files, or "echo", like :
Code:
touch /opt/file-${var}-more.txt
echo "" > /opt/file-${var}-more.txt

# 3  
Old 01-28-2008
Quote:
Originally Posted by sysgate
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

# 4  
Old 01-28-2008
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.
# 5  
Old 01-28-2008
Smilie
Quote:
Originally Posted by 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. Shell Programming and Scripting

Create file from script shell

Hello all :) Here is my code i try to complete: address1="$(ssh root@$machine -x "lxc-info -n $machine-worker1 -H -i")" if //ifthe file addrfile does not exist then create the file addrfile echo "$address1">"$addrfile" fi "$address1">"$addrfile" How, can i... (4 Replies)
Discussion started by: chercheur111
4 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

Shell scripting - need to arrange the columns from multiple file into a single file

Hi friends please help me on below, i have 5 files like below file1 is x 10 y 20 z 15 file2 is x 100 z 245 file3 is y 78 z 23 file4 is x 100 (3 Replies)
Discussion started by: siva kumar
3 Replies

5. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

6. Shell Programming and Scripting

Create a table using shell scripting

Hi Can we create a rectangular table as i have attached in the query . This is primarily for populating the created table with data gathered . Hope I made myself clear ... Pls suggest Thanks (1 Reply)
Discussion started by: ultimatix
1 Replies

7. Shell Programming and Scripting

How to create file in ksh scripting with permission(rw-rw-rw)

Hi, Please provide your inputs.. Thanks in Advance, Mansa (1 Reply)
Discussion started by: mansa
1 Replies

8. Shell Programming and Scripting

Read words from file and create new file using K-shell.

Hi All, Please help me in creating files through K-shell scripts. I am having one file in this format. OWNER.TABLE_NAME OWNER.TABLE_NAME1 OWNER1.TABLE_NAME OWNER1.TABLE_NAME1 I want to read the above file and create new file through k shell script. The new file should looks like this.... (4 Replies)
Discussion started by: bsrajirs
4 Replies

9. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

10. UNIX for Dummies Questions & Answers

file activity (open/closed) file descriptor info using KORN shell scripting

I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Discussion started by: Gary Dunn
3 Replies
Login or Register to Ask a Question