Unix Noobie Needs help with scripting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unix Noobie Needs help with scripting
# 1  
Old 08-01-2005
Unix Noobie Needs help with scripting

I've just begun using/studying Unix and I've run into a problem. I'm attempting to write a script that will replace a string within a textfile with another string, backing up the file before editing it.

This is what I have so far, but I'm getting a "command not found" error.

example input: myscript dog cat text.txt

Code:
#!/bin/csh
mv $3 $3.bak

sed "s/$1/$2/g" $3.bak > $3

If anyone can point me into the right direction, it would be greatly appreciated.
# 2  
Old 08-01-2005
example input: myscript dog cat text.txt

I assume you want to command-line arguments.

Check this out.

Code:
#! /bin/csh

if ( "$#" != 3 )  then
echo " Only 3 arguments are required" 
else
mv "$3" "$3.bak"
sed -e "s/$1/$2/g" "$3.bak" > "$3"
endif

Vino
# 3  
Old 08-02-2005
Hi Vino, thank you for your reply.

This was a really stupid problem. To fix the issue, all I had to do was add the full command directory. ie: /usr/bin/sed "s/$1/$2/g" $3.bak > $3 .

I wish I had come by this simple fix before spending hours on it. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX Scripting

Hi Guys, I need your help. I have a file with around 10,000 lines in which i need to get the machine and owner name and paste in the seperate file. I have multiple entries fr machine and owner i need to fetch the data accordingly. File example: command: /data/esb/etl/bods_exported_script... (20 Replies)
Discussion started by: Vinoth Kumar G
20 Replies

2. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

Hello Experts, I have the following questions to be discussed here at this esteemed discussion forum. I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies

3. UNIX for Advanced & Expert Users

Unix scripting

i need help with this problem this is the problem: Write a script that logs how many users login on/off the system over a 5 minute period. It can run in the foreground, and run 4 times a minute. Set a trap that will not allow a CNTRL-C command, and if a CNTRL-C is excuted store the time and date... (1 Reply)
Discussion started by: sportsmansixty6
1 Replies

4. Shell Programming and Scripting

help while looping simple noobie

hi guys i have linked my lab 15. i have no idea where to start i dont understand whats it asking me. about the screen shot part!.. if someone can take a quick look and help me out with this unix lab that would be great.. i have did the Required Errorlevels Errorlevel #Event Information ... (1 Reply)
Discussion started by: beerpong1
1 Replies

5. Programming

Noobie in C

Hi to everyone , I am learning C language and I have problem with one example from book #include <stdio.h> int main() { char me; printf(“What is your name?”); scanf(“%s”,&me); printf(“Welcome, %s!\n”,me); return(0); } when I want to... (5 Replies)
Discussion started by: solaris_user
5 Replies

6. Shell Programming and Scripting

Unix Scripting

Hi Gurus, I am a system admin in solaris field and ive planned to study unix scripting.ive planned to start reading Mastering Unix scripting by randal.Scripts in that are based on Korn shell(ksh).my question is whether the same scripts can be applied to other shells like bash etc..And... (4 Replies)
Discussion started by: madanmeer
4 Replies

7. UNIX for Dummies Questions & Answers

I need help with a noobie shell script.

My applogies. (1 Reply)
Discussion started by: buttons
1 Replies

8. UNIX for Dummies Questions & Answers

Network noobie question

This is my first attempt in installing a netbsd ever. I'm trying to get myself familiar with some commands and how things work in unix and so far i never knew its this fun. Anyway, unix is our elective here in school and school is gonna start 2 weeks. I'm just trying to get a headstart on this :D... (2 Replies)
Discussion started by: 3rr0r_3rr0r
2 Replies

9. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

10. Solaris

New born noobie with an easy question

I was told on a website that unix can help you make one. I was just wondering how and can you help me with a web page of my own. (1 Reply)
Discussion started by: Shintouku
1 Replies
Login or Register to Ask a Question