sed shell 变量替换 变量含有空格以及单引号问题

时间:2022-12-12 16:48:55

首先假设我想要echo 一个string带有单引号怎么实现呢?

[root@centosTest ~]# echo '1'
1

[root@centosTest ~]# echo "\'1\'"
\'1\'

[root@centosTest ~]# echo ''\''1'\'''
'1'


但是假如我在shell中以变量的形式传递呢?

看下面的脚本

[root@centosTest freshexp]# more sedexptry.sh 
#!/bin/bash
file=$1          #export file
mapping=$2       #mapping config
while IFS="|" read flag old new
do
    echo "flag is "$flag
    echo $old
    echo $new
    sed s/"\($flag  ..\?\)  $old"/"\1  $new"/ $file > $file.tmp
done<$mapping
[root@centosTest freshexp]# more mapping.cfg 
asselv|'1'|'11111'
[root@centosTest freshexp]# sh -x sedexptry.sh test.txt mapping.cfg 
+ file=test.txt
+ mapping=mapping.cfg
+ IFS='|'
+ read flag old new
+ echo 'flag is asselv'
flag is asselv
+ echo ''\''1'\'''
'1'
+ echo ''\''11111'\'''
'11111'
+ sed 's/\(asselv  ..\?\)  '\''1'\''/\1  '\''11111'\''/' test.txt
+ IFS='|'
+ read flag old new
[root@centosTest freshexp]# 



看到没,他的echo竟然是echo ''\''1'\'''

然后在sed中竟然是sed 's/\(asselv  ..\?\)  '\''1'\''/\1  '\''11111'\''/' test.txt

其实我想要的是        sed s/"\(asselv  ..\?\)  '1'"/"\1  '11111'"/ test.txt

其实我的目的是想将文件

+0000000000000060496.,+0000000000000009017.,20130101,"1","quarav","  loandt  >  '$elquar'",,"quarav"
+0000000000000060498.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060499.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060500.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060501.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060502.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '5'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060503.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060504.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060505.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd 
 in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060506.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060507.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '5'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"

中的asselv  =  '1'   替换为 asselv  =  '1003'


在不能解决上面的单引号的问题的时候我想了另一种解决方法:

[root@centosTest freshexp]# more sedexport.sh 
#!/bin/bash
file=$1          #export file
mapping=$2       #mapping config
while IFS="|" read flag old new
do
    echo $flag
    echo $new
    sed s/"\($flag  ..\?  '\)$old"/"\1$new"/ $file > $file.tmp
    mv $file.tmp $file
done<$mapping

一开始运行的不错,但是后来发现了问题,很隐蔽,看一下运行之后的文件就能想到错误错在哪里

[root@centosTest freshexp]# more test2.txt
+0000000000000060496.,+0000000000000009017.,20130101,"1","quarav","  loandt  >  '$elquar'",,"quarav"
+0000000000000060498.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060499.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060500.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111003'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060501.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060502.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '55555'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060503.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060504.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060505.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111003'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060506.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060507.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '55555'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
[root@centosTest freshexp]# ^C
[root@centosTest freshexp]# 
mapping文件如下

[root@centosTest freshexp]# more mapping2.cfg 
asselv|1|11111
asselv|5|55555
[root@centosTest freshexp]# 

看来还是的精确生成如下的sed才行

sed s/"\(asselv  ..\?\)  '1'"/"\1  '11111'"/ test.txt

但是里面的单引号让我头疼不已!!!!





----一个小测试:

[root@centosTest freshexp]# message="a b c"
[root@centosTest freshexp]# echo $message 
a b c
[root@centosTest freshexp]# URL="http://1.1.1.1/1.php?message=MESSAGE&receiver=RECEIVER"
[root@centosTest freshexp]# echo $URL
http://1.1.1.1/1.php?message=MESSAGE&receiver=RECEIVER
[root@centosTest freshexp]# echo $URL|sed “s@MESSAGE@$message@”|sed “s@RECEIVER@$receiver@”^C
[root@centosTest freshexp]# ^C
[root@centosTest freshexp]# echo $URL|sed "s@MESSAGE@$message@"
http://1.1.1.1/1.php?message=a b c&receiver=RECEIVER
[root@centosTest freshexp]# a="'1'"
[root@centosTest freshexp]# echo $a
'1'
[root@centosTest freshexp]# b="sssss'1'ssss"
[root@centosTest freshexp]# echo $b
sssss'1'ssss
[root@centosTest freshexp]# echo $b|sed "s/$a/4"
sed:-e 表达式 #1,字符 7:未终止的“s”命令
[root@centosTest freshexp]# echo $b|sed "s/$a/4/"
sssss4ssss
[root@centosTest freshexp]# aa="'2'"
[root@centosTest freshexp]# echo $b|sed "s/$a/$aa/"
sssss'2'ssss
[root@centosTest freshexp]# 

[root@centosTest ~]# message="a b c"
[root@centosTest ~]# receiver="aa"
[root@centosTest ~]# URL="http://1.1.1.1/1.php?message=MESSAGE&receiver=RECEIVER"
[root@centosTest ~]# echo $URL|sed s@MESSAGE@"$message"@|sed s@RECEIVER@$receiver@
http://1.1.1.1/1.php?message=a b c&receiver=aa
[root@centosTest ~]# echo $URL|sed "s@MESSAGE@$message@;s@RECEIVER@$receiver@"
http://1.1.1.1/1.php?message=a b c&receiver=aa



[root@centosTest ~]# sed 'N;N;s/"//g;s/message=\(.*\)\nreceiver=\(.*\)\nURL=\(.*\)MESSAGE\(.*\)RECEIVER/\3\1\4\2/' a
http://1.1.1.1/1.php?message=a b c&receiver=aa

[root@centosTest ~]# more a
message="a b c"
receiver="aa"
URL="http://1.1.1.1/1.php?message=MESSAGE&receiver=RECEIVER"

[root@centosTest ~]# 





莫名其妙的问题好像解决了,详细如下

[root@centosTest freshexp]# sh -x sedexptry13.sh test2.txt mapping.cfg 
+ file=test2.txt
+ mapping=mapping.cfg
+ IFS='|'
+ read flag old new
+ echo 'flag is asselv'
flag is asselv
+ echo ''\''1'\'''
'1'
+ echo ''\''11111'\'''
'11111'
+ sed 's/\(asselv  ..\?\)  '\''1'\''/\1  '\''11111'\''/' test2.txt
+ IFS='|'
+ read flag old new
[root@centosTest freshexp]# more test2.txt.tmp 
+0000000000000060496.,+0000000000000009017.,20130101,"1","quarav","  loandt  >  '$elquar'",,"quarav"
+0000000000000060498.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060499.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060500.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060501.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060502.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '5'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060503.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060504.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060505.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060506.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060507.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '5'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
[root@centosTest freshexp]# more sedexptry13.sh 
#!/bin/bash
file=$1          #export file
mapping=$2       #mapping config
while IFS="|" read flag old new
do
    echo "flag is "$flag
    echo $old
    echo $new
    #sed s/"\($flag  ..\?\)  "$old""/"\1  "$new""/ $file > $file.tmp
    sed "s/\($flag  ..\?\)  $old/\1  $new/" $file > $file.tmp 
done<$mapping
[root@centosTest freshexp]# 
[root@centosTest freshexp]# more test2.txt
+0000000000000060496.,+0000000000000009017.,20130101,"1","quarav","  loandt  >  '$elquar'",,"quarav"
+0000000000000060498.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060499.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060500.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060501.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060502.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '5'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060503.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060504.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060505.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060506.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060507.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '5'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
[root@centosTest freshexp]# 


现在正式重新测试:

[root@centosTest freshexp]# cp sedexptry13.sh sedexptry14.sh
[root@centosTest freshexp]# chmod 777 *
[root@centosTest freshexp]# more sedexptry14.sh 
#!/bin/bash
file=$1          #export file
mapping=$2       #mapping config
while IFS="|" read flag old new
do
    echo "flag is "$flag
    echo $old
    echo $new
    #sed s/"\($flag  ..\?\)  "$old""/"\1  "$new""/ $file > $file.tmp
    sed "s/\($flag  ..\?\)  $old/\1  $new/" $file > $file.tmp 
    mv $file.tmp $file
done<$mapping
[root@centosTest freshexp]# vi mapping.cfg 


asselv|'1'|'11111'
asselv|'5'|'55555'
[root@centosTest freshexp]# more test2.txt
+0000000000000060496.,+0000000000000009017.,20130101,"1","quarav","  loandt  >  '$elquar'",,"quarav"
+0000000000000060498.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060499.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060500.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060501.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060502.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '5'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060503.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060504.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060505.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060506.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060507.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '5'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
[root@centosTest freshexp]# sh -x sedexptry14.sh test2.txt mapping.cfg 
+ file=test2.txt
+ mapping=mapping.cfg
+ IFS='|'
+ read flag old new
+ echo 'flag is asselv'
flag is asselv
+ echo ''\''1'\'''
'1'
+ echo ''\''11111'\'''
'11111'
+ sed 's/\(asselv  ..\?\)  '\''1'\''/\1  '\''11111'\''/' test2.txt
+ mv test2.txt.tmp test2.txt
+ IFS='|'
+ read flag old new
+ echo 'flag is asselv'
flag is asselv
+ echo ''\''5'\'''
'5'
+ echo ''\''55555'\'''
'55555'
+ sed 's/\(asselv  ..\?\)  '\''5'\''/\1  '\''55555'\''/' test2.txt
+ mv test2.txt.tmp test2.txt
+ IFS='|'
+ read flag old new
[root@centosTest freshexp]# more test2.txt 
+0000000000000060496.,+0000000000000009017.,20130101,"1","quarav","  loandt  >  '$elquar'",,"quarav"
+0000000000000060498.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060499.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060500.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060501.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060502.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '55555'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060503.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060504.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060505.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060506.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060507.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '55555'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
[root@centosTest freshexp]# 

接着执行:

[root@centosTest freshexp]# sh -x sedexptry14.sh test2.txt mapping.cfg 
+ file=test2.txt
+ mapping=mapping.cfg
+ IFS='|'
+ read flag old new
+ echo 'flag is asselv'
flag is asselv
+ echo ''\''1'\'''
'1'
+ echo ''\''11111'\'''
'11111'
+ sed 's/\(asselv  ..\?\)  '\''1'\''/\1  '\''11111'\''/' test2.txt
+ mv test2.txt.tmp test2.txt
+ IFS='|'
+ read flag old new
+ echo 'flag is asselv'
flag is asselv
+ echo ''\''5'\'''
'5'
+ echo ''\''55555'\'''
'55555'
+ sed 's/\(asselv  ..\?\)  '\''5'\''/\1  '\''55555'\''/' test2.txt
+ mv test2.txt.tmp test2.txt
+ IFS='|'
+ read flag old new
[root@centosTest freshexp]# more test2.txt 
+0000000000000060496.,+0000000000000009017.,20130101,"1","quarav","  loandt  >  '$elquar'",,"quarav"
+0000000000000060498.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060499.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060500.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060501.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060502.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '55555'  and     fnpdcd  in  ('C01000000','C02000000','C03000000','C04000000')",,"lastbl"
+0000000000000060503.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '11111'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060504.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '2'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060505.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '1003'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060506.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '4'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
+0000000000000060507.,+0000000000000009019.,20120101,"1","lastbl","  asselv  =  '55555'  and     fnpdcd  in  ('C05000000','C06000000','C07000000')",,"lastbl"
[root@centosTest freshexp]# 

OK,解决!!!!





草稿:

    sed 's/"\($flag  ..\?\)  '$(echo $old)'"/"\1  '$(echo $new)'"/' $file > $file.tmp


sed "s/\(asselv  ..\?  '\)1/\111111/" test.txt


sed "s/\($flag  ..\?\)  '1'/\1  '11111'/" test.txt


sed "s/\($flag  ..\?\)  $old/\1  $new/" test.txt



#!/bin/bash
file=$1          #export file
mapping=$2       #mapping config
while IFS="|" read sou tar
    do
    echo $sou
    echo $tar
    sed s/$sou/$tar/ $file > $file.temp
done<$mapping



"\(asselv  ..\?\)  '1'"   |    "\1  '11111'"


    


"\\(asselv  ..\\?\\)  \'1\'"|"\\1  \'11111\'"






"\(asselv  ..\?\)  '\''1'\''"-------------/"\1  '\''11111'\''"/' test.txt




[db2inst1@scpa test]$ vi 
+ file=test.txt
+ mapping=mapping3.cfg
+ IFS='|'
+ read sou tar
+ sed 's/"\(asselv  ..\?\)  '\''1'\''"/"\1  '\''11111'\''"/' test.txt
+ IFS='|'
+ read sou tar
[db2inst1@scpa test]$ more mapping3.cfg 
"\\(asselv  ..\\?\\)  \'1\'"|"\\1  \'11111\'"
[db2inst1@scpa test]$ 




-----
[db2inst1@scpa test]$ sh -x sedexporttry.sh test.txt mapping3.cfg 
+ file=test.txt
+ mapping=mapping3.cfg
+ IFS='|'
+ read sou tar
+ echo '"\(asselv' '..\?\)' ''\''1'\''"'
"\(asselv ..\?\) '1'"
+ echo '"\1' ''\''11111'\''"'
"\1 '11111'"
+ sed 's/"\(asselv' '..\?\)' ''\''1'\''"/"\1' ''\''11111'\''"/' test.txt
sed:-e 表达式 #1,字符 11:unterminated `s' command
+ IFS='|'
+ read sou tar
[db2inst1@scpa test]$ 






"\\(asselv\ \ ..\\?\\)  \'1\'"|"\\1\ \ \'11111\'"








sed 's/"\(asselv' '..\?\)' '----'\''1'\'---'"/"\1' ''\''11111'\''"/' test.txt










+ sed 's/"\(asselv' '..\?\)' ''\''1'\''"/"\1' ''\''11111'\''"/' test.txt
sed:-e 表达式 #1,字符 11:unterminated `s' command
+ IFS='|'
+ read sou tar
[db2inst1@scpa test]$ more mapping6.cfg 
"\\(asselv\ \ ..\\?\\)  \'1\'"|"\\1\ \ \'11111\'"
[db2inst1@scpa test]$ 




sed "s/"\($flag  ..\?\)  $old"/"\1  $new"/g" $file > $file.tmp


sed s/"\(asselv  ..\?\)  '1'"/"\1  '11111'"/ test.txt




sed s/"asselv  =  '1'"/"asselv  =  '11111'"/ test.txt




$s/\([Oo]ccur\)ence/\1rence/


sed s/"\(asselv  .*\)  '1'"/"\1  '11111'"/ test.txt






sed s/"\(asselv  ..?\)  '1'"/"\1  '11111'"/ test2.txt


.\{m, n\}
sed s/"\(asselv  .\{0, 2\}\)  '1'"/"\1  '11111'"/ test2.txt








sed s/"[\(asselv  ..\)|\(asselv  .\)]  '1'"/"\1  '11111'"/ test.txt




sed s/"\(asselv  ..\?\)  '1'"/"\1  '11111'"/ test.txt




sed s/"\(asselv  ..\?\)  '1'"/"\1  '11111'"/ test.txt






sed s/\(asselv  ..\?\)  '1'/\1  '11111'/ test.txt




sed s/"\(asselv  .*\)  '1'"/"\1  '11111'"/ test.txt