how to write multiple lines to a file using shell script? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

how to write multiple lines to a file using shell script?

Shell Programming and Scripting


Tags
shell, unix, xml

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-19-2011
vel4ever vel4ever is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 7 July 2014, 8:51 PM EDT
Location: Chennai, India
Posts: 121
Thanks: 41
Thanked 1 Time in 1 Post
how to write multiple lines to a file using shell script?

I need to create an xml using shell script, but i first want to know how can i write multiple lines to file using shell script?
Sponsored Links
    #2  
Old 12-19-2011
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 20 October 2014, 6:33 PM EDT
Location: Saskatchewan
Posts: 19,628
Thanks: 815
Thanked 3,334 Times in 3,123 Posts

Code:
cat <<EOF >filetoreplace
a
b
c
d
e
f
g
EOF

You can also append with >>filetoappend.

Also remember you can redirect the output of entire shell loops, not just individual statemenets.
Sponsored Links
    #3  
Old 12-19-2011
vel4ever vel4ever is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 7 July 2014, 8:51 PM EDT
Location: Chennai, India
Posts: 121
Thanks: 41
Thanked 1 Time in 1 Post
hi corona,
Thanks for your reply..but i cant open the file i have created after using the script u have provided..it just error out. i new to shell scripting please help.
    #4  
Old 12-19-2011
CarloM CarloM is offline Forum Advisor  
Registered User
 
Join Date: Oct 2011
Last Activity: 17 October 2014, 7:42 AM EDT
Location: London, UK
Posts: 1,048
Thanks: 110
Thanked 241 Times in 226 Posts
Quote:
Originally Posted by vel4ever View Post
it just error out. i new to shell scripting please help.
It's much easier to help if you specify exactly what the errors are, otherwise we're just guessing.
Sponsored Links
    #5  
Old 12-19-2011
vel4ever vel4ever is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 7 July 2014, 8:51 PM EDT
Location: Chennai, India
Posts: 121
Thanks: 41
Thanked 1 Time in 1 Post
i am saving the document in a remote directory, the file which i have created using the above script is not saved as a text document. when i checked its property its format just says TXT,so i cant able to open it up. Hope this clears.
Sponsored Links
    #6  
Old 12-19-2011
CarloM CarloM is offline Forum Advisor  
Registered User
 
Join Date: Oct 2011
Last Activity: 17 October 2014, 7:42 AM EDT
Location: London, UK
Posts: 1,048
Thanks: 110
Thanked 241 Times in 226 Posts
Open it up with what?

What do you see if you cat the file?
Sponsored Links
    #7  
Old 12-19-2011
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 20 October 2014, 6:33 PM EDT
Location: Saskatchewan
Posts: 19,628
Thanks: 815
Thanked 3,334 Times in 3,123 Posts
Quote:
Originally Posted by vel4ever View Post
i am saving the document in a remote directory, the file which i have created using the above script is not saved as a text document. when i checked its property its format just says TXT,so i cant able to open it up. Hope this clears.
Of course it's an ASCII text document; what else could it be? Some remote hosts are more picky about file extensions than UNIX though. Be sure to give it the extension you want.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
write shell script to rename file shubhig15 Shell Programming and Scripting 7 12-10-2010 04:33 AM
shell script: grep multiple lines after pattern match mirfan Shell Programming and Scripting 1 08-10-2010 05:00 PM
how to write shell script to extract lines we want rainboisterous Shell Programming and Scripting 6 06-10-2010 11:48 PM
How to write a shell script to notify when certain texts appear in a file? acider Shell Programming and Scripting 1 01-17-2010 02:09 PM
how to write a shell script that print the last modified file ? FunnyWolF Shell Programming and Scripting 5 08-13-2008 02:25 AM



All times are GMT -4. The time now is 06:22 AM.