Results 1 to 3 of 3
I have about 7 '*.cgi files' in /cgi directory and 1 insert.pl file in /bin . All these files have one line of code which is :
PHP Code:
use ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-12-2012 #1Just Joined!
- Join Date
- Dec 2009
- Posts
- 67
Using 'sed'
I have about 7 '*.cgi files' in /cgi directory and 1 insert.pl file in /bin . All these files have one line of code which is :
I would like to replace the use bin path to another path in all those files.PHP Code:use bin = /path/to/directory
Is this line of code correct to do so :
How do I execute this command for both the *.cgi files in /cgi and insert.pl in /bin at one time?Code:find /cgi -name "*.cgi" -exec sed -i "%s,/old/path,/new/path,g" '{}' \;
- 11-13-2012 #2Just Joined!
- Join Date
- Sep 2007
- Location
- India
- Posts
- 2
Something like this:
Regards,Code:$ cat work/test1/a.cgi use bin = /path/to/directory Some other lines $ cat work/test1/b.cgi use bin = /path/to/directory Some other lines $ cat work/dir2/c.pl use bin = /path/to/directory This is a perl file $ find work/test1/ work/dir2/ -type f \( -iname "*.cgi" -or -iname "*.pl" \) work/test1/b.cgi work/test1/a.cgi work/dir2/c.pl $ for fl in $(find work/test1/ work/dir2/ -type f \( -iname "*.cgi" -or -iname "*.pl" \)); do echo $fl; sed '/use bin/ s!/path/to/directory!/path/to/directory1!g' $fl > $fl.bak ; mv -v $fl.bak $fl ; done work/test1/b.cgi `work/test1/b.cgi.bak' -> `work/test1/b.cgi' work/test1/a.cgi `work/test1/a.cgi.bak' -> `work/test1/a.cgi' work/dir2/c.pl `work/dir2/c.pl.bak' -> `work/dir2/c.pl' $ cat work/test1/a.cgi use bin = /path/to/directory1 Some other lines $ cat work/test1/b.cgi use bin = /path/to/directory1 Some other lines $ cat work/dir2/c.pl use bin = /path/to/directory1 This is a perl file
Jadu
- 11-13-2012 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 18
What about this one?
Code:(find /cgi -name "*.cgi"; find /bin -name "insert.pl") | while read -r; do sed -ri "s,^(use bin =) /old/path$,\1 /new/path,g" "$REPLY" done


Reply With Quote
