gpt4 book ai didi

linux - 如何从多行文件中读取变量?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:02:53 27 4
gpt4 key购买 nike

我正在尝试从一个多行文件中读取,每行有多个变量。有四个变量:item、price、max_qty 和 min_qty。该文件如下所示:

item price
min_qty max_qty

我试过:

while IFS=' ' read -r first second third fourth; do
echo "$first $second $third $fourth
done

这是行不通的。我希望输出为:

item price min_qty max_qty

我还考虑过以某种方式用空格替换新行,然后从该行读取。我不想实际更改文件。

最佳答案

阅读两次:

while read -r first second && read -r third fourth; do 
echo "$first $second $third $fourth"
done < file

关于linux - 如何从多行文件中读取变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55692928/

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