Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My logfile has the following format:

Dec 26 13:11:48 kernel: ACCEPT IN=br0 OUT=vlan1 SRC= DST= LEN=44 TOS=0x00 PREC=0x00 TTL=63 ID=9312 DF PROTO=TCP SPT=11733 DPT=80 WINDOW=5840 RES=0x00 SYN URGP=0 OPT (020405B4) 

Now i'm trying to remove some dispensable information to make the output better readable and well arranged and put it into a new file.

The result should look like this and should only have the following information:

Dec 26 13:11:48 TCP SPT=11733 DPT=80

How to do it?

share|improve this question
up vote 2 down vote accepted
awk '{sub(/PROTO=/, "", $17); print $1,$2,$3,$4,$17,$18,$19}' < logfile.log > processed-logfile.log
share|improve this answer
thanks, i understood the print part, but the sub part doesn't work for me? i get the error message: awk: line 1: runaway string constant ", $17); pr ... – NES Dec 26 '10 at 13:02
i think there is a missing double quote a the sub replacement option – NES Dec 26 '10 at 13:07
yes there is, sorry about that. i fixed it now. – immibis Dec 26 '10 at 13:23
You can omit the input redirection. – Dennis Williamson Dec 26 '10 at 20:12

Try awk to select the wanted columns with print statements to place them in the desired order.

For instance, if you wanted the PID (process ID) of process "foo" on your system, you could run

ps -ef | grep foo | grep -v grep | awk '{ print $2 ; }'
share|improve this answer
could you provide a syntax example since i'm a relative newbie with commandline processing like this? – NES Dec 26 '10 at 12:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.