script to search and replace deprecated functions
Posted
by
user573881
on Stack Overflow
See other posts from Stack Overflow
or by user573881
Published on 2011-01-14T05:49:38Z
Indexed on
2011/01/14
5:53 UTC
Read the original article
Hit count: 619
Hi,
I am using the following script to search and replace the deprecated functions in a file with the newer ones.
5 for strFile in `ls deprecated_functions_search_and_replace.txt `
6 do
7 sed "s/ereg_replace[^\(]*(\([^,]*\),/preg_replace\1('#'.\2.'#',/g" $strFile > temp_file
8 mv $strFile $strFile".bakup"
9 mv temp_file $strFile
10
11 sed "s/eregi[^\(]*(\([^,]*\),/preg_match\1('#'.\2.'#i',/g" $strFile > temp_file
12 mv $strFile $strFile".bakup"
13 mv temp_file $strFile
14
15 sed "s/ereg[^\(]*(\([^,]*\),/preg_match\1('#'.\2.'#',/g" $strFile > temp_file
16 mv $strFile $strFile".bakup"
17 mv temp_file $strFile
18
19 sed "s/split[^\(]*(\([^,]*\),/preg_split\1('#'.\2.'#',/g" $strFile > temp_file
20 mv $strFile $strFile".bakup"
21 mv temp_file $strFile
22
23 sed "s/mysql_escape_string/mysql_real_escape_string/g" $strFile > temp_file
24 mv $strFile $strFile".bakup"
25 mv temp_file $strFile
26
27 sed "s/set_magic_quotes_runtime(0)/\/\/set_magic_quotes_runtime(0)/g" $strFile > temp_file
28 mv $strFile $strFile".bakup"
29 mv temp_file $strFile
30
31 sed "s/ini_get('safe_mode')/false/g" $strFile > temp_file
32 mv $strFile $strFile".bakup"
33 mv temp_file $strFile
34
35 sed "s/session_register('\(.*\)')/$_SESSION['\1']=$\1/g" $strFile > temp_file
36 mv $strFile $strFile".bakup"
37 mv temp_file $strFile
38
39 sed "s/session_unregister('\(.*\)')/$_SESSION['\1']=''/g" $strFile > temp_file
40 mv $strFile $strFile".bakup"
41 mv temp_file $strFile
42
43 done
However, when I run this script I am getting an error saying:
sed: -e expression #1, char 60: invalid reference \2 on `s' command's RHS
sed: -e expression #1, char 52: invalid reference \2 on `s' command's RHS
sed: -e expression #1, char 50: invalid reference \2 on `s' command's RHS
sed: -e expression #1, char 51: invalid reference \2 on `s' command's RHS
I am unable to figure out whats going wrong. Someone please help me. Regards.
© Stack Overflow or respective owner