Write a script that takes 2 arguments


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Write a script that takes 2 arguments
# 1  
Old 03-24-2006
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
# 2  
Old 03-24-2006
Give this a try:

Code:
#!/usr/bin/sh

touch $2
echo $1 > $2

Then :

Code:
# ./your_script HELLO myfile

# 3  
Old 03-24-2006
PHP 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
# 4  
Old 03-24-2006
Sounds like you tested this on an important file...don't do that.

">" will overwrite your file, ">>" will add to your file.
# 5  
Old 03-24-2006
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
# 6  
Old 03-24-2006
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.
# 7  
Old 03-24-2006
thanks tmarikle
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

write() system call arguments

Hi, I'm trying to understand the arguments from this system call, can someone help me figure it out? write(1, "/home/nick/11sp/fred\n", 27/home/nick/11sp/fred) = 27 for argument 1, i know it is a file descriptor which specifies standard output. Argument 2, i believe is "what is to be... (4 Replies)
Discussion started by: l flipboi l
4 Replies

2. UNIX for Dummies Questions & Answers

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (5 Replies)
Discussion started by: ajaira
5 Replies

3. UNIX for Advanced & Expert Users

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (1 Reply)
Discussion started by: ajaira
1 Replies

4. Shell Programming and Scripting

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (1 Reply)
Discussion started by: ajaira
1 Replies

5. UNIX for Dummies Questions & Answers

script takes the whole filename instead of just extension

I am running my script from "/abc/" this path and it has no ".csv files" but has a ".txt" files namely temp1.txt My script goes as below, wherein it is suppose to find files with *.txt extension and *.csv extension in another path namely "/abc/xyz/": #!/bin/ksh PATH1="/abc/xyz/" value="*.csv... (1 Reply)
Discussion started by: wolverine999
1 Replies

6. Shell Programming and Scripting

Script that takes in variables, and outputs to another text or script file

Ok, I sort of need to create a command files that will be ftped to another server to run. I have some input variable that will need to be read, and then transformed into another script file. Here are some examples. Server 1: outputCmd.sh passing in ./outputCmd.sh nh8oaxt Release_4_0... (1 Reply)
Discussion started by: orozcom
1 Replies

7. Shell Programming and Scripting

need inputs on how i can change my script to reduce amount of time the script takes

HI , I have a list1 which consists of data that i have to search and a list2 which has the files that need to be searched .So basically i am using list1 on list2 to see if list1 data is present if found replace it .I have written the code using foreach loop for each list .This is taking the... (1 Reply)
Discussion started by: madhul2002
1 Replies

8. Shell Programming and Scripting

script takes params

i want to write a shell script that can be run as ./deployPortal.sh -version 5.1.2 -portlet -exportall how can i do that? version param is required. bu the others are optional. in first step i only want to read 5.1.2, is portlet selected ? and is exportall selected ?? can you... (2 Replies)
Discussion started by: keromotti
2 Replies

9. Solaris

NFS write failed for server.....error 11 (RPC: Server can't decode arguments)

Hello! I have a Linux nfs server (called server100 below) with a export nfs. My problem is that the Solaris client (called client100 below) doesn't seems to like it. In the Solaris syslog I got following messages (and after a while the solaris client behave liked its hanged/to buzy). Also see... (3 Replies)
Discussion started by: sap4ever
3 Replies

10. Shell Programming and Scripting

To Write a Shell script that takes two arguments.

How to write a shell script tht takes two arguments.The first being a line of text,the second being your newly created file(x no:of lines and content of ur choice). 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.... (3 Replies)
Discussion started by: bobby36
3 Replies
Login or Register to Ask a Question