The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2006
Skunkie Skunkie is offline
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 09:50 AM.. Reason: Trying to make it more friendly to read
  #2 (permalink)  
Old 10-02-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

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


Code:
echo "$var1" > file.txt
cat $var2 file.txt
  #3 (permalink)  
Old 10-02-2006
Skunkie Skunkie is offline
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
  #4 (permalink)  
Old 10-02-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
awk is a good choice. If perl is an option that works very well also.
  #5 (permalink)  
Old 10-02-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
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..
Sponsored Links
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0