I use awk a fair bit for parsing logs; I have never seen anything like this: I have six file containing a number of lines; I want the ones containing "100", and to choose which columns to print
me:~/tmp> grep 100 *.dl.tst
outputs what I expect:
100 139M 100 139M 0 0 6376k 0 0:00:22 0:00:22 --:--:-- 6539k
100 139M 100 139M 0 0 6677k 0 0:00:21 0:00:21 --:--:-- 6579k
100 139M 100 139M 0 0 6022k 0 0:00:23 0:00:23 --:--:-- 6093k
100 139M 100 139M 0 0 13.9M 0 0:00:10 0:00:10 --:--:-- 14.3M
100 139M 100 139M 0 0 14.3M 0 0:00:09 0:00:09 --:--:-- 14.7M
100 139M 100 139M 0 0 13.2M 0 0:00:10 0:00:10 --:--:-- 13.3M
as does:
me:~/tmp> grep 100 *.dl.tst|awk '{print$0}'
100 139M 100 139M 0 0 6376k 0 0:00:22 0:00:22 --:--:-- 6539k
100 139M 100 139M 0 0 6677k 0 0:00:21 0:00:21 --:--:-- 6579k
100 139M 100 139M 0 0 6022k 0 0:00:23 0:00:23 --:--:-- 6093k
100 139M 100 139M 0 0 13.9M 0 0:00:10 0:00:10 --:--:-- 14.3M
100 139M 100 139M 0 0 14.3M 0 0:00:09 0:00:09 --:--:-- 14.7M
100 139M 100 139M 0 0 13.2M 0 0:00:10 0:00:10 --:--:-- 13.3M
Why then does $1
become the file name:
me:~/tmp> grep 100 *.dl.tst|awk '{print$1}'
shpr002.20201124_141036.dl.tst:
shpr003.20201124_141036.dl.tst:
shpr004.20201124_141036.dl.tst:
hipr002.20201124_141036.dl.tst:
hipr003.20201124_141036.dl.tst:
hipr004.20201124_141036.dl.tst:
And $2
:
me:~/tmp> grep 100 *.dl.tst|awk '{print$2}'
0
0
0
0
0
0
I logged out and back in in case my shell (bash) was screwed up; no change... what am I doing wrong?
Output from grep 100 *.dl.tst | awk '{print$1}' | head -n1 | od -c
(some of the alpha characters have been substituted by x
; the list above had been edited/obfuscated)
0000000 x s h p r 0 0 2 x x x . x x x .
0000020 x x x x . c o m . 2 0 2 0 - 1 1
0000040 - 2 4 _ 1 4 1 0 3 6 . d l . t s
0000060 t : \r \n
0000064
grep 100 *.dl.tst | awk '{print$1}' | head -n1 | od -c
. The file name is normal, that's grep adding the file name to the output, but it should also be there when youprint $0
. I'm thinking you might have some non-printing characters which is why I asked for that output. – terdon♦ Nov 24 '20 at 16:39