我有幾個以字符串「file」開頭的文件,然後是一個數字(file1,file2等)。linux從幾個文件中獲取特定的字段
這些文件的內容是相似的,看起來像這樣
file1:
$xx_ at 10.0 "$elt_(0) coordinates 636.46 1800.37 9.90"
$xx_ at 10.0 "$elt_(1) coordinates 367.78 1263.63 7.90"
對於每一個文件,我想只保留元素的索引,只是座標後2個數字字段(在同一個文件或另一個文件):
文件1:
0 636.46 1800.37
1 367.78 1263.63
我試圖做的是這樣的(但是這是不正確的)
find . -name "file*"|while read fname; do
echo "$fname"
for line in $(cat "$fname") do
FS="[_() ]"
print $7 "\t" $10 "\t" $11 > $fname
done
done
是(在'$ elt_數0)'與索引相同? – mstruebing