gpt4 book ai didi

linux - 用文件中的下划线替换空格 (bash)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:06:50 28 4
gpt4 key购买 nike

我目前正在编写一个脚本,该脚本使用“mapfile”访问另一个文件并将其放入一个数组中。但是,输入的文件包含一些空格,脚本将其读取为新的数组条目。

如何在我导入的文件正文中用下划线替换空格?我只看到有关如何替换文件名的说明,而不是其中的内容。

提前致谢!如果您需要任何进一步的说明,请告诉我。

最佳答案

给定:

$ cat file
1 2 3 4

你可以使用sed:

$ sed 's/[[:space:]]/_/g' file
1_2_3_4

那么你可以这样做:

$ mapfile -t arr < <(sed 's/[[:space:]]/_/g' file)

关于linux - 用文件中的下划线替换空格 (bash),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45218786/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com