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 question ace2000 Shell Programming and Scripting 7 04-18-2008 12:39 PM
cgi script question zilla30066 Shell Programming and Scripting 1 05-03-2007 11:56 AM
script question fusionjd Shell Programming and Scripting 1 02-05-2006 03:38 PM
script question shad0w75 UNIX for Dummies Questions & Answers 2 06-19-2003 01:53 PM
Script Question merlin UNIX for Dummies Questions & Answers 2 11-20-2001 07:57 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-08-2006
Registered User
 

Join Date: Apr 2006
Posts: 13
Script question

Can anyone help with these scripts? Im new to this and struggling. Thank you for your help.

Pre-requisites

Create a file with x amount of lines in it, the content of your choice. (Have already done this)

Script 1

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

Once complete save the script.


Script 2

Take a copy and amend the above script so that it now inserts the first argument into the middle of the file.

Note! Again the original file must retain it original name
Forum Sponsor
  #2  
Old 04-08-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,614
Please make sure that you have read our rules. And note:
(6) Do not post classroom or homework problems.
  #3  
Old 04-09-2006
Registered User
 

Join Date: Apr 2006
Posts: 13
Help!

I have a script that takes two arguments.
The first argument is a string and the second argument is the name of a file.
The script inserts the string into the first line of the file and then saves it.
The problem im having is that it is saving the wrong message to the file.

e.g. File1 has the following data:
Line1
Line2

I invoke the script as follows.

./Script1 Hello File1


Script1 contains the following data:

cat $2 > tempFile
MESSAGE=$1
awk ' NR==1 { printf "%s\n", $MESSAGE } { printf $0 "\n" } ' tempFile > $2
rm tempFile


The result should be:
Hello
Line1
Line2

But I am getting the following result:
Line1
Line1
Line2


Any ideas on what i am doing wrong?

Thank you.
  #4  
Old 04-09-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Threads merged and closed.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:23 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