2

If I run

sudo pico /var/log/lighttpd/website/error.log

I get a very long file, and I cannot see last lines. If I run:

sudo tail -f /var/log/lighttpd/website/error.log | awk '{print $1 "--"  $2}'

I don't get anything ? What am I doing wrong ?

Also, how can I move to a specific line using pico editor ?

thanks

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
aneuryzm
  • 1,714
  • 5
  • 26
  • 41

3 Answers3

3

You would better to use some pager program like less. It tries not to load the whole file into memory, so it works well with large files. In less you can move to a specific line by typing :123 where 123 is line number you need.

As for tail - are you getting anything without awk? Or with sudo tail -n 10 -f <log>?

Scott Pack
  • 14,907
  • 10
  • 53
  • 83
rvs
  • 4,125
  • 1
  • 27
  • 31
2

The -f flag in tail means "Keep the tail process running and if the file changes, chuck them onto STDOUT". Basically, it's a neat way of actively watching a log file.

I believe the pipe will wait for the first program to finish writing to STDOUT before throwing the output into awk. Because of the -f flag, tail never quits (until you tell it) so nothing ever gets piped into awk. Therefore nothing gets printed.

Try the second command without the -f. If you're looking for -f functionality but also with mangling the output with awk, I'm not sure what the answer is, short of writing a custom script to do it...

growse
  • 8,020
  • 13
  • 74
  • 115
  • Nope, pipe won't wait for the first program. There might be some buffer, but I've never faced any problems and noticeable delays with it using `tail -f | grep <...>` or `tail -f | awk <...>` – rvs Mar 23 '11 at 10:42
  • 1
    I stand corrected. – growse Mar 23 '11 at 10:55
0

tail -f never quits as long as the file still exists (and I think after that too). Nothing gets passed through the pipe until the first process has died.

If you want the functionality of tail -f (i.e. monitoring the file) while still piping it through awk, try watch "tail /var/log/lighttpd/website/error.log | awk '{print \$1 \"--\" \$2}'"

jho
  • 131
  • 5