Replacing variable is files in same directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing variable is files in same directory
# 1  
Old 02-02-2012
Replacing variable is files in same directory

Hi all,

I'm writing a script to get values from the user and replace it in another file in the same directory.
Code:
/usr/bin/sediff 's/$PROJECT/'$PROJECT'/' /ananth/TEMPLATE

TEMPLATE is the file I want to replace the variable PROJECT from the script I'm writing but Im not getting it done. Is there any way to solve this?


thanks
Ananth

Moderator's Comments:
Mod Comment How to use code tags

Last edited by vbe; 02-02-2012 at 06:09 AM..
# 2  
Old 02-02-2012
Try to replace the single quotes with double quotes, single quotes prevent shell expanding of the variables.
# 3  
Old 02-02-2012
Frankling,
I tried that but it didnt work either.
# 4  
Old 02-02-2012
Quote:
Originally Posted by Ananthdoss
Hi all,

I'm writing a script to get values from the user and replace it in another file in the same directory.
Code:
/usr/bin/sediff 's/$PROJECT/'$PROJECT'/' /ananth/TEMPLATE

TEMPLATE is the file I want to replace the variable PROJECT from the script I'm writing but Im not getting it done. Is there any way to solve this?


thanks
Ananth
Code:
 
/usr/bin/sediff "s/\$PROJECT/$PROJECT/" /ananth/TEMPLATE

# 5  
Old 02-03-2012
Hi
I'm getting the following ERROR: Unable to open policy at s/$PROJECT/"input i give"/.
ERROR: No such file or directory
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving files to a directory with a variable name

I have this shell script which i am going to package into an application: cd /Users/william/Desktop Cleaning; mkdir "date"; cp ~/Desktop/* ~/"date"; how would i point to the directory with the name unknown to cp? (2 Replies)
Discussion started by: ws1
2 Replies

2. Shell Programming and Scripting

To find ls of similar pattern files in a directory by passing the variable.

Hi, I have file in my $datadir as below :- SAT_1.txt SAT_2.txt BAT_UD.lst BAT_DD1.lst DUTT_1.txt DUTT_la.txt Expected result :- should get all the above file in $<Filename>_file.lst Below is my code :- for i in SAT BAT DUTT do touch a.lst cd $datadir (1 Reply)
Discussion started by: satishmallidi
1 Replies

3. Shell Programming and Scripting

Replacing exact directory variable

I am making a script to relocate a project file. I have all of the variables in place and everything is working except: the first variable changes everytime it passes thru a loop. The second is a constant value. when I run that it does what I want...but incorrectly. It is finding... (2 Replies)
Discussion started by: gentlefury
2 Replies

4. Shell Programming and Scripting

Move files to variable directory

Im trying to move my files to a variable folder i've just created. Step 1 is working fine. mkdir /sdcard/DCIM/Photos/`date +%Y%m%d` Step 2 is not working mv /sdcard/DCIM/100ANDRO/*.jpg /sdcard/DCIM/Photos/`date +%Y%m%d` What am i doing wrong? (2 Replies)
Discussion started by: dihavs
2 Replies

5. Shell Programming and Scripting

Parsing all the files in the directory and replacing them

Hi, I would like to parse all the files (*.c and *.h) in the sub-directories and if *.c or *.h files are found I would like to append a string and place it in the same directory. How do I do that? For example: I'm gonna operate on dir1 level. $dir1/subdir1/test.h should be done as... (1 Reply)
Discussion started by: suryaemlinux
1 Replies

6. Shell Programming and Scripting

Append variable texts to the beginning of each line in all files in a directory

I am writing a code to append some numbers in the beginning of each line in all the files present in a directory. The number of files are really huge. The files are numbered as 1.sco, 2.sco, 4.sco (Note: 3.sco is missing). The files currently look like this: 1.sco 2 3 5 6 6 7My task is to... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

7. UNIX for Dummies Questions & Answers

Replacing in a variable

Hi, If I have a variable var1 ='TH 12/1234' How can I set this too in a script var1 ='TH 12~1234' Bearing in mind "/" might be in a difference place each time and that the "/" might not even exist each time the variable is set. Thanks (3 Replies)
Discussion started by: belfastbelle
3 Replies

8. Shell Programming and Scripting

replacing new lines in all files of a directory containing old lines

Hi all, I am trying to replace a few lines with other lines of all files in a directory which contain those few lines. say - there are some 10 files in a dir having the same 4 lines as 1.txt at the starting 1.txt line 1 line 2 line 3 line 4 ....................................... (1 Reply)
Discussion started by: rooster005
1 Replies

9. UNIX for Dummies Questions & Answers

Replacing $ in variable

hi I have a variable like k=$DESTDIR/$PKG/$VERSION I want to replace each $ in string k with say "XXX". so that k becomes like this "XXXDESTDIR/XXXPKG/XXXVERSION" when I use echo $k | sed -e "s/\$/XXX" it actually passes expanded of variables $DESTDIR, $PKG and $VERSION to sed. ... (10 Replies)
Discussion started by: ashish_uiit
10 Replies

10. Shell Programming and Scripting

replacing variable values in all files in directories

Hi Guys, I have some basic unix knowlege but new to shell scripting. I want to replace variable values in all files in sub-directories. Any sugestion will be helpful. Example. Main Dir: X Sub Dir: X1, X2, X3, X4, X5, X6.... X10 Each sub directory has file which contains variable A = 10. ... (3 Replies)
Discussion started by: newtoshell
3 Replies
Login or Register to Ask a Question