3

I'm using this to filter a logging file and I'm trying to squeeze as much relevant detail as I can onto the console:

 awk -F " " '{$1=$2=$4=$5=$6=$7=""; print $0}'

This is my raw input:

149.177.5.87 - [08/Feb/2017:18:14:20 +0000] 18:14:20:408 18:14:20:435 11140 "GET /2/forecast/KBBL/lastSave HTTP/1.1"  200 43 27 27

and this is my awk'd output:

  [09/Feb/2017:11:27:01     "GET /2/data/load/KBBL/2017-01-25/daily?startDate=2017-01-01&endDate=2019-12-31&firstWeekday=0 HTTP/1.1" ?startDate=2017-01-01&endDate=2019-12-31&firstWeekday=0 401 - 1 1

It's not so obvious on this web page, but on the console it's clear that awk is adding blank spaces to separate the columns that I have set to "".

i.e. there's a bigger gap at the start of the line and between the timestamp and the info.

Can I get rid of it with a better awk command?

Nifle
  • 34,998
Adam
  • 198

1 Answers1

3

It's possible to do in awk but this is imo easier

nifle@xanadu ~/tmp
$ L='149.177.5.87 - [08/Feb/2017:18:14:20 +0000] 18:14:20:408 18:14:20:435 11140 "GET /2/forecast/KBBL/lastSave HTTP/1.1"  200 43 27 27'

nifle@xanadu ~/tmp
$ echo $L |  cut -d ' ' -f 3,8-
[08/Feb/2017:18:14:20 "GET /2/forecast/KBBL/lastSave HTTP/1.1" 200 43 27 27
Nifle
  • 34,998