看板 Linux 關於我們 聯絡資訊
※ 引述《prolog (波卡)》之銘言: : 假設我有一個list 其內容為: : a1 a2 a3 : b1 b2 b3 : c1 c2 c3 : 我希望用cat list 將內容存成變數 : 希望${file1}為a1 b1 c1那一列 ${file2}為a2 b2 c2那一列... : 請問我該如何做? : 如果只有一列我目前知道,但將不同列存成不同變數目前沒有頭緒 : #!/bin/bash : for FILE in `cat list` : do : xxx : done : 以上 謝謝! lloyd@hilltop$ cat list a1 a2 a3 b1 b2 b3 c1 c2 c3 lloyd@hilltop$ sh list1.sh This file1 = a1 b1 c1 This file2 = a2 b2 c2 lloyd@hilltop$ cat list1.sh #!/bin/sh file1="" file2="" IFS="" for i in $(cat list) ; do L1=$(echo $i|cut -d" " -f1) L2=$(echo $i|cut -d" " -f2) file1="$file1 $L1" file2="$file2 $L2" done unset IFS echo "This file1 = $file1" echo "This file2 = $file2" lloyd@hilltop$ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.60.21
prolog:先感謝您 我研究一下XD 07/24 22:32