I have c shell script , basically i want to find out the string "/usr/inter/wat/dat/out" and replace with "/home/trw/sh" in multiple input files
Please advise. We use Linux red hat server.
Cshell 1:
------------
#!/bin/csh
set file_name="/usr/inter/wat/out/bill_validate.txt"
old="/usr/inter/wat/dat/out"
new="/home/trw/sh"
sed "s/$old/$new/g" file >new_file
Check the delimiters for substitution.
1 Like
thank you so much for your email.
Is it possible to replace a string without creating new file?
And also i have to do it for 35 files...
How to do it generic for all the 35 files in command prompt?
Thanks in advance.
old="/usr/inter/wat/dat/out" new="/home/trw/sh" sed "s/$old/$new/g" file >new_file
old="/usr/inter/wat/dat/out"
new="/home/trw/sh"
sed "s/$old/$new/g" file >new_file
I'm afraid that won't work. Try it, it will crash. You have to use a different separator character than /
in this situation:
old="/usr/inter/wat/dat/out"
new="/home/trw/sh"
sed "s!$old!$new!g" file >new_file
In your C shell script you will loop through the files, and apply the sed command to each file in turn. Or, using GNU sed, you can say sed -i "s/A/B/g" *.txt
and it will edit them all in place, making a temporary file in the background for each one.