[英]how could I read and use the text file values (comma separated or line separated) in an awk command
[英]read a file line by line and assign the values to variable as comma separated
我有以下 a.txt 文件:
abc,
def,
ghi
我想逐行閱讀它,並將其作為逗號分隔值存儲在變量中
var1=abc,def,ghi
我是 shell 腳本的新手請幫忙
我的嘗試:
name="file.txt"
while IFS=read -r line
do
names=`echo $line`
done < "name"
它只顯示 varibale 的值 ghi
您不是在串聯,而是在每次循環中都替換names
變量。
分配變量時無需使用echo
。
name="file.txt"
names=
while IFS=read -r line
do
names="$names$line"
done < "name"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.