awk與csh 搭配傳入外部變數的問題 - Linux

Table of Contents

我有兩個檔案

檔名 1.txt
內容 3-6 aaaa.tif
4 bbbb.tif
9-7 cccc.tif....

檔名 2.txt
內容 1
2
3-6
4
5-0
9-7


我如果直接打
set a = 3-6
awk '{if ($1==a) print $0}' a=$a 1.txt

會出現

3-6 aaaa.tif


但是如果我把他寫成cshell
#!/bin/csh
foreach a(`cat 2.txt`)
awk '{if ($1==a) print $0}' a=$a 1.txt
end

他永遠只會出現
4 bbbb.tif

也就是說 他只讀是整數的 如果第一列是xx-xx的話
他就會跳過

想請問各位神手 能否幫在下解決此一問題?
非常謝謝

--

All Comments

Regina avatarRegina2015-03-27
所以你想做? 拿2.txt內容取出1.txt對應內容的東西?
Rebecca avatarRebecca2015-03-28
測了一下你的寫法,顯示出來的值挺正常的...
Mia avatarMia2015-03-29
3-6 aaaa.tif , 4 bbbb.tif , 9-7 cccc.tif
Iris avatarIris2015-03-31
因為我用mac 所以不知道是不是因為這個原因...
Dinah avatarDinah2015-04-05
手上沒有mac....你可以看一下你執行的shell是哪個