The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script takes params keromotti Shell Programming and Scripting 2 06-06-2008 04:15 AM
NFS write failed for server.....error 11 (RPC: Server can't decode arguments) sap4ever SUN Solaris 3 05-08-2008 05:20 AM
To Write a Shell script that takes two arguments. bobby36 Shell Programming and Scripting 3 04-05-2007 05:44 PM
shell script takes long time to complete ozzman Shell Programming and Scripting 12 02-05-2007 08:25 PM
Passing arguments to a script Kevin Pryke Shell Programming and Scripting 3 06-14-2002 06:06 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-24-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
Write a script that takes 2 arguments

hi
i would be grateful for some help on the following q.

"Write a script that takes two arguments. The first being a line of text, the second being your newly created file. The script should take the first argument and insert it into the very top ( the first line) of the file named in your second argument.

Note! The file must retain the original name

thanks a million

i have a feeling its involving sed
Reply With Quote
Forum Sponsor
  #2  
Old 03-24-2006
Registered User
 

Join Date: Feb 2005
Location: Canada
Posts: 131
Give this a try:

Code:
#!/usr/bin/sh

touch $2
echo $1 > $2
Then :

Code:
# ./your_script HELLO myfile
Reply With Quote
  #3  
Old 03-24-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
Thumbs down inserted text deleted file content

I need to add text on top of an original file, this method deleted my file and just left HELLO on top..

Any suggestions
Reply With Quote
  #4  
Old 03-24-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Sounds like you tested this on an important file...don't do that.

">" will overwrite your file, ">>" will add to your file.
Reply With Quote
  #5  
Old 03-24-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
that worked fine to append to end of line, how do you append on top of file, or in the middle say 5 lines down. Thanks for the quick response
Reply With Quote
  #6  
Old 03-24-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Now you are asking questions beyond parameters and simple redirection. This kind of question comes up alot, try searching the forums for examples using "sed". Once you have searched a few times, you'll find your own answers very quickly. If you get really stuck, post your question again, there is alot of help here.
Reply With Quote
  #7  
Old 03-24-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
thanks tmarikle
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:29 PM.


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