Using scripts to create output files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using scripts to create output files
# 1  
Old 04-16-2013
Using scripts to create output files

been messing around with linux for a few months...not too good yet. thinking about taking a class or something, this #### is hard.......anyway, im trying to make an output file using the input from a prompt. heres basically what i have now (random example)
Code:
echo -n "Please enter your name: "
read name
##
echo "This is a new file."
echo "It was created by $name."

basically, all ive done is set the variable, im trying to figure out how to take that variable and use it in an output file...i am at a loss, been working for like 2 hours, i have tried a few different things, but not the results im looking for.

would really appreciate any tips

Last edited by Corona688; 04-16-2013 at 04:43 PM..
# 2  
Old 04-16-2013
Read up on redirection
Code:
echo "hello"

sends to screen
Code:
echo "hello" >> myfile

sends that to the file called myfile, in append mode
but beware of > as it creates a new file
as in
Code:
echo "hello" >> myfile
echo "goodbye" > myfile
cat myfile

will leave you only with "goodbye"

Last edited by joeyg; 04-16-2013 at 03:35 PM..
# 3  
Old 04-16-2013
thanks, I know a little about redirection from the command line, is it the same when I do it from a script? I can't get it to work
# 4  
Old 04-16-2013
Yes, shell script and command lines are usually the exact same language. (Usually, but not always.)

What exactly did you try, and in what way did it "not work"? Be specific.
# 5  
Old 04-16-2013
i am trying to create an output file from a script, here is exactly what i did:

Code:
#!/bin/bash
##
##
echo -n "Please enter your name: "
read name
##
echo "This is a new file."
echo "It was created by $name"
 
cat > newfile

i dont know how to make the output end up in the file, the output is going to the standard out (the screen) instead of in the file. newfile is empty.
# 6  
Old 04-16-2013
Code:
#!/bin/bash
##
##
echo -n "Please enter your name: "
read name
##
echo "This is a new file." > newfile
echo "It was created by $name" >> newfile

This User Gave Thanks to hanson44 For This Post:
# 7  
Old 04-16-2013
Thanks, that works great
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to create separate files but not include specific field in output

I am trying to use awk to create (in this example) 3 seperate text file from the unique id in $1 in file, if it starts with the pattern aa. The contents of each row is used to populate each text file except for $1 which is not needed. It seems I am close but not quite get there. Thank you :). ... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

3. Shell Programming and Scripting

How I can create this Shell scripts?

Hi friends you can solve my question about make 3 shell scripts? Thanks for all! (1 Reply)
Discussion started by: dakota
1 Replies

4. UNIX for Dummies Questions & Answers

awk to match multiple regex and create separate output files

Howdy Folks, I have a list that looks like this: (file2.txt) AAA BBB CCC DDD and there are 24 of these short words. I am matching these patterns to another file with 755795 lines (file1.txt). I have this code for matching: awk -v f2=file2.txt ' BEGIN { while(... (2 Replies)
Discussion started by: heecha
2 Replies

5. Shell Programming and Scripting

Script to read input and output files and child scripts

I have a directory where i have *.sas; *.pl;*.sh and *.c scripts I need to find out what are the child scripts and input output files for each script: say I have a shell script which calls a perl script and a sas script: In my first line I want I a) the parent script name; b) the... (1 Reply)
Discussion started by: ramky79
1 Replies

6. Shell Programming and Scripting

Create Bash shell scripts corresponding to windows bat files

Experts, I am newbie in shell scripting. I want to write Bash shell scripts corresponding to windows bat files. I have installed cygwin at c:\cygwin and i am trying to crate the sh file using vi editor. i am not able to understand how to use linux/unix convention for the code. following is my... (1 Reply)
Discussion started by: rajuchacha007
1 Replies

7. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

8. Shell Programming and Scripting

Find duplicate value comparing 2 files and create an output

I need a perl script which will create an output file after comparing two diff file in a directory path: /export/home/abc/file1 /export/home/abc/file2 File Format: <IP>TAB<DeviceName><TAB>DESCRIPTIONS file1: 10.1.2.1.3<tab>abc123def<tab>xyz.mm1.ppp.... (2 Replies)
Discussion started by: ricky007
2 Replies

9. Shell Programming and Scripting

FTP is using shell scripts create ? for file

ftp -n -v <<EOF verbose open 3.57.40.79 user infodvlp pr0gram ascii lcd /home/a501420038/GLA/Success_Load/ cd /ftp/SrcFiles/csg/InstruAsia/ get AU_Success_Log.txt close quit EOF Please help on this, this gives the out put "AU_Success_Log.txt?" As question mark in the last what will... (1 Reply)
Discussion started by: a501420038
1 Replies

10. UNIX for Dummies Questions & Answers

shell scripts to create 100 users

Hello i need a shell script to create 100 users i am running hp-ux......... startegy is something like this craete a shell script !/bin/ksh counter=1 while do { useradd usr$counter passwd usr$counter # here begins my problem when i say passwd usr$counter #it again prompts... (9 Replies)
Discussion started by: xiamin
9 Replies
Login or Register to Ask a Question