跳到主要內容

Pass an outside variable into awk

awk -v var=value_of_wherever '$1 >= var' input_file

See the following example

#/bin/bash

let i=1
for ((i=1; i<=5; i++)); do # this is also called the C-like loop

echo 'i = ' $i
echo -n 'Now see awk result: '
awk -v test_value=$i '$1 == test_value' data_file
# use -v option in awk to assign the variable $i
# to test_value,
which is passed inside the awk
# command inside quotes.

done

留言

這個網誌中的熱門文章

國道通行費比較表

A FREEway that is not really FREE. 有人想過 做個圖看看嗎 ? 資料來源: freeway.gov.tw 方案一【一段式收費】:無免費里程,單一費率0.82元/公里。 方案三【三段式收費】:每日每車免費里程20公里,標準費率1.2元/公里(行駛里程 小於200公里), 長途費率0.9元/公里(行駛里程大於等於200公里) 相關新聞: 國道計程 「北高估348元」 | 蘋果日報 : 自由電子報 - 國道計程收費民調 免費20公里呼聲高 : 國道計程收費 下半年上路 - Yahoo!奇摩新聞 :