Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
shell script
Name: neelima_123 Date: December 20, 2006 at 04:07:18 Pacific OS: UNIX CPU/Ram: 2.26GHZ, 504MB of RAM
Comment:
Can any one send me a shell script to search and replace a string in a directory
Since it's sed it, doesn't change text in place. You have to redirect the output to a temporary file and then change the file name.
0
Response Number 3
Name: neelima_123 Date: December 20, 2006 at 21:18:50 Pacific
Reply:
Thanks for ur response,But I want to replace a sting in a file with another string
for ex :There is a directory "ABCD" which contain 50 files ,among these 50 files there are 20 files which conatin a particular string(lets say "hello world").I want to replace "hello world" with "hello something"...
Sorry for tat ambigious question.
neelima
0
Response Number 4
Name: neelima_123 Date: December 20, 2006 at 21:47:25 Pacific
Reply:
I forgot to specify that there can be any number of sub folders in that directory
neelima
0
Response Number 5
Name: nails Date: December 21, 2006 at 09:11:18 Pacific
Reply:
Did you even bother reading the other thread? Place the following commands in a file called 'gres' and make it executable:
# D & R's gres file="myfilename" pattern=$1 replacement=$2 A="`echo | tr '\012' '\001' `" sed -e "s$A$pattern$A$replacement$A" $file # end gres
Execute it like this:
gres "hello world" "hello something"
If you want to seach a directory tree, use find:
find . -type f -print|while read myfile do echo "$myfile" done
Or use the recursive option of ls:
ls -1R|while read myfile do if [[ -f $myfile ]] then echo "$myfile" fi done
Summary: Write a shell script file called letter1. After running the script, it will prompt the user, for an English alphabet, confirm the alphabet chosen, and then search the current directory for all the fil...
Summary: Shell Scripting -- Variables In the main script i have exported the variable and accessing it in another file but when i echo the value the value of the exported variable is not viewable . below are ...