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
Simple Script mojoman Shell Programming and Scripting 6 05-12-2008 12:55 AM
simple script help ali560045 Shell Programming and Scripting 4 01-24-2008 01:24 AM
simple script ali560045 Shell Programming and Scripting 1 01-22-2008 12:41 AM
simple awk script... moxxx68 Shell Programming and Scripting 3 01-24-2005 12:17 AM
simple script hedrict UNIX for Dummies Questions & Answers 4 02-23-2004 12:15 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-02-2006
Registered User
 

Join Date: Oct 2006
Posts: 2
Simple Script Help

Hi, First of all i would just like to say Hi to you all.
Ive just started trying to learn a bit of UNIX and am hopefully going to get on a course in the next couple of weeks to expand my knowledge of it however i have run into some problems surrounding one of the scripts i was asked to write as part of an introduction and was wondering if any of you here could possible help.

Im not asking for an answer more some pointer in the right direction as i have been looking through books and over the net for quite some time now.


The aim is the following.

Write a script that takes two arguments. The first being a line of text, the second being a newly created file. The script should take the first argument and insert it into the very top line of the file named in the second argument. The file must retain the original name.

Here is what i have done this far.



Code:
var2="$HOME/script1/Lateralus"     -----The address of the file to add to

echo "Please Enter your Input"   -----Line to ask for user input 
read var1                                   -----Read the input to a variable
echo "Your Input was the following : $var1"        --Echo input 

echo "This will be added to the top line of file : $var2"  --Echo File address

vi +0 $var2            ----Enter VI at Line 0 for filename in var2
O                         ----Start insert above current line

Now im stuck however. How can i take what i have entered into $var1 and insert it into the file. Maybe i am wrong to be using VI to do this script however i am new to this and need some guidence.

Eternally greatful to anyone that can help. Thanks for your time

Last edited by Skunkie; 10-02-2006 at 06:50 AM. Reason: Trying to make it more friendly to read
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-02-2006
Registered User
 

Join Date: Sep 2006
Posts: 1,448
something like this without using sed/awk etc


Code:
echo "$var1" > file.txt
cat $var2 file.txt
Reply With Quote
  #3 (permalink)  
Old 10-02-2006
Registered User
 

Join Date: Oct 2006
Posts: 2
Later on i am going to need to adapt this to add the input to the centre of the file.

On this knowledge would u advice i start to look into sed/awk??

If so is there anywhere that you would advice starting.
Got all these books but i dont know where to start looking :

Thank you for your Help
Reply With Quote
  #4 (permalink)  
Old 10-02-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,502
awk is a good choice. If perl is an option that works very well also.
Reply With Quote
  #5 (permalink)  
Old 10-02-2006
Registered User
 

Join Date: Sep 2006
Posts: 1,448
Quote:
Originally Posted by Skunkie
Later on i am going to need to adapt this to add the input to the centre of the file.

On this knowledge would u advice i start to look into sed/awk??

If so is there anywhere that you would advice starting.
Got all these books but i dont know where to start looking :

Thank you for your Help
In unix, these are the tools (sed/awk/grep/perl etc) that will help you for such problems. These tools use regular expressions a lot, so it might be confusing at first for beginners.
here
might help you get started.
Personally, i like Python to solve my problems..
Reply With Quote
Google UNIX.COM
Reply

Tags
regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:35 AM.


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

Content Relevant URLs by vBSEO 3.2.0