如何在bash编程中替换多行文本 [英] How to replace multi-line text in bash programming

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

问题描述

我要替换以下文本

text := a \
        b \
        c

,并带有以下内容:

text := d \
        e \
        f

在bash文件中为

.

in bash file.

我尝试了不同版本的"sed",但没有一个有效,例如:

I have tried different versions of 'sed', but none of them worked e.g.:

old_path='text := a \\\n\t\tb \\\n\t\tc'
new_path='text := d \\\n\t\te \\\n\t\tf'
sed -i -e "s%old_path%new_path%g" text.txt

推荐答案

如果您不介意使用 Perl ,请尝试:

if you do not mind using Perl try:

~ ❱ perl -pe 's/ ((?=[a-z]).)/" ".chr(ord($1)+3)/eg' file
text := d \
        e \
        f 
~ ❱ 

您字符的ASCII码是: 100 101 102
因此,如果您向他们添加 3 ,它们从 a b c 变为 d e f

the ASCII code for your character is: 100, 101 and 102
Thus if you add 3 to them they from a b c become d e f

这篇关于如何在bash编程中替换多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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