AWK列

2016-08-16 31 views
-2

使用一個固定的記錄長度的文件,並試圖從134位和160長度檢查空間的某一列的所有空間 這裏空間檢查是我:AWK列

awk file.test |awk '{ teststr=substr($0,134,160); if (teststr ~ /^[[:space:]]*$/) {print "ALLSPACES"teststr"end"} else {print "NOTALLSPACES"teststr"end"} } ' 

它總是返回else部分eventhough上有teststr

NOTALLSPACESTHIS IS A TESTend 
NOTALLSPACES    end 
NOTALLSPACES    end 

值有什麼不對awk的語句/正則表達式

+0

@ Barmar..thanks後的* $幫助格式我question..Oppsie這是一個錯字.. ny命令與結尾:但仍然不起作用 –

+0

我試過你的腳本,它的工作。不要忘記,awk中的列位置'substr()'是基於1的,而不是基於0的。 – Barmar

+0

@Balmar,我試了一遍,它的工作..謝謝! –

回答

0

錯字是CAU唱這個問題..更新AWK聲明以上正確答案

awk file.test |awk '{ teststr=substr($0,134,160); if (teststr ~ /^[[:space:]]*$/) {print "ALLSPACES"teststr"end"} else {print "NOTALLSPACES"teststr"end"} } ' 

TYPE:在空間

+0

不要把問題的解決方案放在答案中。 – Barmar

+0

錯字是什麼?你說''問題是在問題中的錯字,而不是真正的代碼。 – Barmar