Board logo

标题: [问题求助] 【已解决】Shell替换文件内容问题 [打印本页]

作者: BatAli    时间: 2015-4-8 17:31     标题: 【已解决】Shell替换文件内容问题

本帖最后由 BatAli 于 2015-4-9 10:53 编辑

主程序:
  1. #!/bin/bash
  2. arrline=();
  3. arrchan=();
  4. i=1
  5. while read a
  6.    do
  7.      eval $(echo $a|awk -F":" '{for(x=1;x<=NF;x++) {print "arrline["x"]="$x}}');
  8.      arrchan[i]=${arrline[2]}
  9.      let i+=1;
  10.    done < 111.txt
  11. for chan in ${arrchan[@]}  
  12.     do  
  13.       sed -i "/name/ s/\(.*=\).*/\1$chan/" 222.txt
  14.     done
  15. exit
复制代码
111.txt内容:
baidu:baidu 123
222.txt内容:
name=test

问题:
111.txt文件中的内容有空格,不能正确替换222.txt文件中的内容
作者: Batcher    时间: 2015-4-8 18:54

  1. #!/bin/bash
  2. arrline=();
  3. arrchan=();
  4. i=1
  5. while read a; do
  6.     eval $(echo $a|awk -F":" '{for(x=1;x<=NF;x++) {print "arrline["x"]=" "\x22" $x "\x22"}}')
  7.     arrchan[$i]="${arrline[2]}"
  8.     let i+=1
  9. done < 111.txt
  10. for chan in "${arrchan[@]}"; do
  11.     sed -i "/name/ s/\(.*=\).*/\1$chan/" 222.txt
  12. done
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2