Discussion:
awk的REGEX想吃變數
(时间太久无法回复)
就是要贏
2013-01-22 01:28:01 UTC
Permalink
各位好

我目前的問題在於我想用awk去對字串作比對

這個字串為timestamp,其形式假設為0122092513

表示為01月22號09時25分13年

由於使用者可以自行選擇要哪個月份的資料

所以有個變數是month,其值為使用者輸入

我想從data中撈出所有month月份的資料

我的寫法如下

if($2~/"$month".*/)print //語法不正確,但重點為變數那邊

這樣寫的時候

awk完全撈不到資料

請問我該如何解決呢?

謝謝各位的指點

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.170.196.107
k***@gmail.com
2013-02-09 13:57:10 UTC
Permalink
Post by 就是要贏
各位好
我目前的問題在於我想用awk去對字串作比對
這個字串為timestamp,其形式假設為0122092513
表示為01月22號09時25分13年
由於使用者可以自行選擇要哪個月份的資料
所以有個變數是month,其值為使用者輸入
我想從data中撈出所有month月份的資料
我的寫法如下
if($2~/"$month".*/)print //語法不正確,但重點為變數那邊
這樣寫的時候
awk完全撈不到資料
請問我該如何解決呢?
謝謝各位的指點
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.170.196.107
If I understood you correctly, you were trying to pass a variable
from the shell to awk.

In that case, you might like to try:

awk -v month=$month ....
and refer to the variable simply as "mont

Loading...