我有以下输入:
Value1|Value2|Value3|Value4@@ Value5|Value6|Value7|Value8@@ Value9|etc...
在我的bash脚本中,我想用一个换行符替换@@
。我已经用sed尝试了各种方法,但我没有任何运气:
line=$(echo ${x} | sed -e $'s/@@ /\\\n/g')
最终我需要将整个输入解析成行和值。也许我做错了。我计划用换行符替换@@
,然后通过设置IFS='|'
来分割值来循环输入。如果有更好的方法,请告诉我,我仍然是shell脚本的初学者。
7条答案
按热度按时间q0qdq0h21#
使用纯BASH字符串操作:
或者在单步中执行:
nkcskrwz2#
这会有用的
用新行替换
@@
3mpgtkmj3#
我建议使用tr函数
例如:
gev0vcfq4#
终于让它工作了:
在\n周围添加单引号似乎出于某种原因有所帮助
guicsvcw5#
如果你不介意使用Perl:
eoxn13cs6#
怎么样:
cngwdvgl7#
这就结束了使用perl来做这件事,并给出了一些简单的帮助。
replace_string.sh