請教bash script問題 - Linux

Xanthe avatar
By Xanthe
at 2009-07-24T22:25

Table of Contents

※ 引述《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$

--
Tags: Linux

All Comments

Carolina Franco avatar
By Carolina Franco
at 2009-07-25T08:52
先感謝您 我研究一下XD

Fedora 11 Display setup

Ula avatar
By Ula
at 2009-07-24T15:45
請問Fedora 11 是不是沒有了system-config-display這個指令? 還是有別的指令可以叫出顯示設定? - ...

DRBL/Clonezilla「集中管理環境」進階課程(台中)

Jessica avatar
By Jessica
at 2009-07-24T15:29
8月25/26日 DRBL/Clonezilla「集中管理環境」進階課程(台中)(含中小學教師研習) 上課地點:台中市中部科學工業園區科園路22號 國網中心 中部事業群 電腦教室 A 上課時間: 2009/8/25 (二) ~ 2009/8/26 (三) 09:30 ~ 16:30 上課總天數:2 天,共計 ...

USB隨身碟讀取.存取

Ida avatar
By Ida
at 2009-07-24T14:58
各位大大好: 我是linux新手,當要跑matlab程式時,要如何操作才能讀取USB隨身碟內的 程式,而matlab的檔名該儲存為何?還是linux無法讀隨身碟??? 請各位大大幫幫忙 - ...

pidgin不能使用yahoo messenger

Daniel avatar
By Daniel
at 2009-07-24T13:23
好像是這個樣子 不過msn到是可以使用 -- ncyu phyedu_99n,ofo TFHS_57__326,cgu abnormal face book http://www.facebook.com/home.php my space http://www.myspace.com/468176328 ...

無法yum

Isla avatar
By Isla
at 2009-07-24T13:16
做了一個容器在 /etc/yum.repo.d/ 內 裡面只有我新建的容器名稱為 centos.repo 檔案分享的ftp為 http://192.168.1.25/pub/ 容器內容為 [centos] name=centos baseurl= http://192.168.1.25/pub ...