|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help with basic Shell programming
Hi
I am trying to write a shell program which takes in three parameters: the file name of text document, the original word and the new word e.g. $ replace.sh blah.txt Dev Shed So this should convert all the "Dev" strings in the blah.txt to "Shed" Following is my script #! /bin/csh set file1=$argv[1] set file2=$argv[2] set file3=$argv[3] sed 's/file2/file3/ file1 when I run it, it says cannot open file1. Can somebody help me with this. I am a beginner and its really frustrating me. Thanx |
|
#2
|
||||
|
||||
|
Moving this thread to the unix forum as it has nothing to do with C programming. As for your specific problem, you need to refer to your variables as $file1, $file2 etc.
Code:
#! /bin/csh set file1=$argv[1] set file2=$argv[2] set file3=$argv[3] sed 's/$file2/$file3/' $file1 Note the $ signs in the sed line.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
|
#3
|
|||
|
|||
|
Thank You. I am totally new to this forum thats why I kind of don't know where to post what. Thanx again
![]() |
|
#4
|
|||
|
|||
|
Now it seems as if the sed command does not work because it is basically giving me the same output when I run replace.sh blah.txt Dev Shed
|
|
#5
|
|||
|
|||
|
sed 's/$file2/$file3/' $file1 <---- will never expand $file[23]
sed "s/$file2/$file3/" $file1 <--- does it see the difference ! girl? boy ? 1 chromosome ![]() are you beginning... so do it the proper way csh is a fantastic tool on the command line (my preferred) but the BSD-guys did not complete the job, so NEVER, NEVER, NEVER write csh SCRIPTS it's buggy, to be portable prefer the old BOURN, else KSH, BASH or other. Last edited by guggach : October 24th, 2004 at 04:22 AM. Reason: typo |
|
#6
|
|||
|
|||
|
Hi
Hi guys. Thanx for being so helpful. I just have one last thing that I can not figure out. I wanna make permanent changes to the actual file using sed command. How do I do it. It seems like it does not change the actual contents of the file . thanx
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Need help with basic Shell programming |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|