Tail -f, awk and redirection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tail -f, awk and redirection
# 1  
Old 07-13-2006
Tail -f, awk and redirection

I want to run tail -f to continuously monitor a log file, outputing a specific field to a second log file. I can get the first portion to work with the following command:

tail -f log | awk '{if ($1 == "Rough") print $5}'

also:

awk '{if ($1 == "Rough") print $5}' <(tail -f log)

The problem is I can not redirect the stdout from these commands to a second log file. Any ideas? Thanks!


-Mikolai Fajer-
# 2  
Old 07-13-2006
Code:
tail -f log | awk '{if ($1 == "Rough") print $5}'  | tee mySecondFile.txt

# 3  
Old 07-13-2006
Quote:
Originally Posted by vgersh99
Code:
tail -f log | awk '{if ($1 == "Rough") print $5}'  | tee mySecondFile.txt

Interestingly enough the above command does not output to the file or the STDOUT (at least for me!). The following command does work:

tail -f log | tee mySecondFile.txt

As does:

awk '{if ($1 == "Rough") print $5}' | tee mySecondFile.txt

I then tried:

tail -f log | awk '{if ($1 == "Rough") print $5}' | tee mySecondFile.txt &

Curiously enough, this does work! I waited about a minute, then a long sequence of output (about 20+ lines) appeared on STDOUT and only the last five or so appeared in mySecondFile.txt. This repeats every few minutes, with again only the last few lines being placed into mySecondFile.txt. The ouput placed into mySecondFile.txt is overwritten each time. What did work is:

tail -f log | awk '{if ($1 == "Rough") print $5 | "tee mySecondFile.txt"}'

This works perfectly! Thank you for bringing the tee program to my attention.


-Mikolai Fajer-
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to tail sed and awk in one line?

Hello, I am trying to create an iptables script with tail ,sed and awk. 1st Request: Search keyword "secret" in access.log file 2nd Request: Get first column matching lines (ip address) 3rd Request: Save it to a file This is what I did so far: grep.sh #!/bin/bash while true; do tail... (23 Replies)
Discussion started by: baris35
23 Replies

2. How to Post in the The UNIX and Linux Forums

Usage of tail command in .awk

Hi, I want to do file format using awk script, for that i wan to use 'tail'. Here is the scenario. I will be having set of files in a directory. Those files i need to write to another directory with same file name, but while writing the file to out directory, i need to write the last line as... (3 Replies)
Discussion started by: Venkata Madhu
3 Replies

3. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

4. Shell Programming and Scripting

AWK / tail Issue

Hello, I am using a tail command to fetch the line before last in a log file. the two last lines are as followed: 11-01-16 11:55:45.174 | CClientObject::InitTraceLevelInCache Starting CClientObject::InitTraceLevelInCache End I am doing a awk statement to gather only the numeric... (1 Reply)
Discussion started by: LiorAmitai
1 Replies

5. Shell Programming and Scripting

awk redirection

Hi everyone i am facing a very strange problem . see below is my code #awk <do something> file 1 > file2 Now the problem is whenever i am redirecting the output to file2 it creates the file2 but of 0 size. i don't know what is the reason but it is very important to me to redirect the... (11 Replies)
Discussion started by: aishsimplesweet
11 Replies

6. Shell Programming and Scripting

awk output redirection to file

I have a system stat command running which generates data after 5 sec or so. I pass this data to awk and do some calculation to present the data differently. Once done now I want to pass this data to file as and when generated but doesn't work..unless the first command completes successfully.... (6 Replies)
Discussion started by: learnscript
6 Replies

7. Shell Programming and Scripting

Error with redirection in awk

I'm trying to find average of values in 2nd column in some files. Filenames have following pattern eg: tau_2.54_even_v1.xls tau_2.54_odd_v1.xls tau_1.60_v1.xls tau_800_v1.xls #!/bin/bash for file in pmb_mpi tau xhpl mpi_tile_io fftw ; do for f in "2.54" "1.60" "800" ;do if... (2 Replies)
Discussion started by: vishwamitra
2 Replies

8. UNIX for Dummies Questions & Answers

AWK Output not working with tail -f

Hi , I have Continuous updating log file. I want to continuously scan that file using "tail -f " and execute a shell command like "date" command when that particular keyword is detected . I am using awk to acheive it but not suceeded so far. However when I use "cat" instead of tail -f this... (3 Replies)
Discussion started by: scott_tiger
3 Replies

9. Shell Programming and Scripting

How do I feed numbers from awk(1) to tail(1)?

Hello, I am too daft to remember how to properly feed numbers that I've extracted with awk(1) to tail(1). The actual question is probably a lot more simple than the context, but let me give you the context anyway: I've just received some email that was sent with MS Outlook and arrived in... (8 Replies)
Discussion started by: ropers
8 Replies

10. Shell Programming and Scripting

awk two file redirection

Hi, i use awk -F to print three variable delimited by comma $1 $2 $3 if $2=="" i want to extract this information missing from another file using awk -v + some process. but the problem i can't use the two awk together cause of redirection there's a solution. note: i can't use another... (1 Reply)
Discussion started by: kamel.seg
1 Replies
Login or Register to Ask a Question