【问题标题】:Read a file and put specific values to an array [closed]读取文件并将特定值放入数组[关闭]
【发布时间】:2019-08-29 06:28:51
【问题描述】:

我是 bash 脚本的新手。我有一个包含一些值的文件。我想将特定键的所有值放入 bash 中的数组中。文件如下所示。

file.properties
name=val1
name=val2
name=val3
age=val4

我想读取这个文件并将所有名称值放入 bash 中的一个数组中。

【问题讨论】:

标签: bash shell file-read


【解决方案1】:

您可以尝试以下方法:

#!/bin/bash
while read -r line; do
    arr=("${arr[@]}" "$line")
done < <(grep name= file.properties | sed "s/name=//")
echo "${arr[@]}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    • 1970-01-01
    • 2015-07-05
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多