在论坛上看的 自己这里记录一下 好学习的 原链接是http://bbs.linuxtone.org/thread-17186-1-2.html

# cat A
a
x
d

# cat B
EXPORT TO 'D:\test\org.ixf' OF IXF MESSAGES 'D:\test\org.msg' SELECT * FROM org;
EXPORT TO 'D:\test\org.ixf' OF IXF MESSAGES 'D:\test\org.msg' SELECT * FROM org;
EXPORT TO 'D:\test\org.ixf' OF IXF MESSAGES 'D:\test\org.msg' SELECT * FROM org;

怎么样实现这个呢?

EXPORT TO 'D:\test\a.ixf' OF IXF MESSAGES 'D:\test\a.msg' SELECT * FROM a;
EXPORT TO 'D:\test\x.ixf' OF IXF MESSAGES 'D:\test\x.msg' SELECT * FROM x;
EXPORT TO 'D:\test\d.ixf' OF IXF MESSAGES 'D:\test\d.msg' SELECT * FROM d;

方法1

paste A B | awk '{gsub(/org/,$1);$1="";print}'

方法2

 
    
  1. [root@localhost test]# cat bb.sh  
  2. #!/bin/bash 
  3. count=0 
  4. for line in `cat A` 
  5.  do 
  6.    ((count++)) 
  7.    sed -i "$count s/org/$line/g" B 
  8. done 
  9. [root@localhost test]# cat B 
  10.  EXPORT TO 'D:\test\a.ixf' OF IXF MESSAGES 'D:\test\a.msg' SELECT * FROM a;
    EXPORT TO 'D:\test\b.ixf' OF IXF MESSAGES 'D:\test\b.msg' SELECT * FROM b;
    EXPORT TO 'D:\test\c.ixf' OF IXF MESSAGES 'D:\test\c.msg' SELECT * FROM c;

方法3

awk '{getline i <"A";gsub("org",i,$0)}1' B