update a string variable and use in....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting update a string variable and use in....
# 1  
Old 07-10-2008
update a string variable and use in....

Hello Forun,

i have a variable searchpath="/home/shailesh/project/debug"
i want to make it like searchpath="/home/shailesh/project/debug/*.mk"

and want to use this like for finding all *.mk files in debug folder.

for f in "$searchpath" `find -type f`;
do
sed "s/$old_path/$project_path/g" "$f" > $TFILE && mv $TFILE "$f"
done

how i can go for this. pls help


BR
Shailesh
# 2  
Old 07-10-2008
Code:
searchpath="/home/shailesh/project/debug/*.mk"
searchdir=$(dirname $searchpath)
searchspec=$(basename $searchpath)

for f in $(find $searchdir -type f -name $searchspec);
do
    sed "s/$old_path/$project_path/g" "$f" > $TFILE && mv $TFILE "$f"
done

If it matches a very large number of files you may need to replace the for loop with a while read loop.
# 3  
Old 07-10-2008
string

but how to convert searchpath="/home/shailesh/project/debug" to
searchpath="/home/shailesh/project/debug/*.mk"
shailesh
# 4  
Old 07-10-2008
I already converted it??? What do you mean?
# 5  
Old 07-10-2008
string

i mean by which command you changed that variable
my variable is only
searchpath="/home/shailesh/project/debug"

i want to add /*.mk on the tail of this variable like
newvar=something operation on searchpath

and newvar is like
newvar="/home/shailesh/project/debug/*.mk"
# 6  
Old 07-10-2008
Quote:
Originally Posted by shailesh_arya
i mean by which command you changed that variable
my variable is only
searchpath="/home/shailesh/project/debug"

i want to add /*.mk on the tail of this variable like
newvar=something operation on searchpath

and newvar is like
newvar="/home/shailesh/project/debug/*.mk"
I don't think you need to combine the pattern of the file and the path because in the find command u need to use it separate. anyway if you want add the pattern in the end of the path you can do it like this.

searchpath="/home/shailesh/project/debug"
newvar="${searchpath}/*.mk"
echo $newvar
# 7  
Old 07-10-2008
string

thx. its working
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check if string variable is a subset of another string variable

Below is my ksh shell script where I need to check if variable fileprops is a subset of $1 argument. echo "FILE PROPERTY: $fileprops" echo "PARAMETER3: $1" if ; then echo "We are Good. $line FILE is found to be INTACT !! " else echo... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Python update variable name in for loop

Hello all, Not sure if this question has been answered already. I have some xml Element variable as below: child19 = core_elem_dcache.find('stat') child20 = core_elem_dcache.find('stat') child21 = core_elem_dcache.find('stat') child22 = core_elem_dcache.find('stat'Next I... (2 Replies)
Discussion started by: Zam_1234
2 Replies

3. Shell Programming and Scripting

Update value of variable

Hallo all.. I'm running in windows 7 and cygwin instaled so i can use linux command on that. I want to update the value of some variable that i stored in a file. How do I update it. this is my file look like.. variable.txt partisi1=25 partisi2=25 partisi3=25 partisi4=25 how can i... (1 Reply)
Discussion started by: weslyarfan
1 Replies

4. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

Makefile doesn't update $< variable

Hello guys, I could use advise from more experienced guys about my Makefile. In short, the problem with my Makefile is that $< doesnt change inside my rule. Here is my Makefile: # Makefile for CORE CC = gcc.exe AS = as.exe AR = ar.exe INCLUDE = \ -I../lib/tomcrypt/inc \... (1 Reply)
Discussion started by: Kodreanu
1 Replies

7. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

8. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

9. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

10. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies
Login or Register to Ask a Question