这个和我的 previous question 有点相关。现在我正在处理一个长字符串:
sed -b -i.old $inifile \
-e "s/a_very_long_pattern_i_should_problably_improve/terribly_long_replace_string"
有没有办法让它格式正确(即缩进且不超过 80 个字符)?使用反斜杠会添加额外的空格:
$ echo 'first_part'\
> 'second_part'
first_part second_part
最佳答案
$ echo 'first_part'\
> 'second_part'
first_part second_part
Bash 连接相邻的字符串文字。
例如,如果您echo "first_part""second_part"
,您将得到
第一部分第二部分
但是,如果您echo "first_part""second_part"
,您将得到first_partsecond_part
因此,请利用这一点为您服务
-e "s/a_very_long_pattern_i_should_problably_improve/terribly_long_replace_string"
你可以尝试做类似的事情
sed -b -i.old $inifile \
-e "s/a_very_long_pattern_"
"i_should_problably_improve/"
"terribly_long_replace_string"
关于string - 如何在 bash 中处理长字符串并仍然获得格式良好的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37857867/