如何用unix中的另一组行替换文件中的一组行? [英] how to replace a set of lines in a file with another set of lines in unix?

查看:22
本文介绍了如何用unix中的另一组行替换文件中的一组行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用 unix 中的另一组行替换文件中的一组行?

how to replace a set of lines in a file with another set of lines in unix ?

#!/usr/bin/ksh
export text1='log_file=$LOG_PATH${UNISON_JOB}".log"'
export text2='\. \$\{env_path\}set_test_log_file\.ksh'
export text3='log_file\=\$LOG_PATH\$\{UNISON_JOB\}\"\.log\"'

echo $text1
echo $text2
echo $text3

for file in `grep -il ${text1} SANDEEP`
do
sed 's/${text3}/${text2}/g' $file > /$file.tmp
mv /$file.tmp $file
echo $file
done

我尝试了上面的代码,但它不起作用.它的 kshell .here sandeep 是我正在搜索的文件名.

i tried the above code but its not working . its kshell .here sandeep is the file name i m searching.

推荐答案

对于带引号的 sed,我喜欢把整个命令写到一个文件中,然后执行这个文件:像这样:

For sed with the quote, I like to write whole command into a file, then execute this file: something like this:

echo "s/${text1}/${text2}/g" > a.sed
sed -f a.sed < inputFile > tmp && mv tmp inputFile
rm -f a.sed

这样可以省去很多处理那些引用的麻烦.

that will save a lot of trouble to deal with those quote thing.

这篇关于如何用unix中的另一组行替换文件中的一组行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆