awk output redirection to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk output redirection to file
# 1  
Old 03-03-2010
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.
Code:
nicstat-1.22/nicstat.Ubuntu7.i386 -i eth4 5 | awk '{print $1 " " ($3+$4)/1024" MBps"}'

This prints something like this:
Code:
Time 0 MBps
17:02:41 0.00254883 MBps
17:02:46 0.00296875 MBps


I want this to be directed to file say /tmp/foo but then I do :
Code:
nicstat-1.22/nicstat.Ubuntu7.i386 -i eth4 5 | awk '{print $1 " " ($3+$4)/1024" MBps"}' > /tmp/foo

It never gets added to foo file.
Thanks for your attention and help.

Last edited by Scott; 03-03-2010 at 08:09 PM.. Reason: Please use code tags
# 2  
Old 03-03-2010
Try this:

Code:
nicstat-1.22/nicstat.Ubuntu7.i386 -i eth4 5 | awk '{print $1 " " ($3+$4)/1024" MBps" > /tmp/foo}'

# 3  
Old 03-03-2010
Thanks for attention . Doesn't work the file even doesn't get created..
# 4  
Old 03-03-2010
Hi.

Can you explain what your /tmp/foo file does look like after running your command?

Is it possible that what you are running is going to standard error, and not standard output.

I.e., would this work:
Code:
nicstat-1.22/nicstat.Ubuntu7.i386 -i eth4 5 2>&1 | awk '{print $1 " " ($3+$4)/1024" MBps"}' > /tmp/foo

# 5  
Old 03-03-2010
/tmp/foo is empty file after running the command. The output does goes to stdout not the error but just to make sure I tried your suggestion couldn't get to work.
Thanks..
# 6  
Old 03-03-2010
After the re-direction does the output still appear on the screen?

It might be using an alternate file descriptor.

is nicstat.Ubuntu7.i386 the (archaically named) program? Is there a man page for it?
# 7  
Old 03-03-2010
It can be found here:
Nicstat - Siwiki
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk file redirection issue

So I'm writing a script which tries to parse human-readable addresses. Part of it is this: print $2, implode(A,1,AN," "), CITY, PROV, POST, COUNTRY, CITYCOUNT>2; CITYCOUNT is a variable between 0 and 3 counting the number of words in a city name. I'm trying to prnt 1 wherever that's greater... (5 Replies)
Discussion started by: Corona688
5 Replies

2. Shell Programming and Scripting

Command output redirection to file issues

Hi, I have a peculiar issue w.r.t redirecting the command output to a file when using loop. I am redirecting command output to same file in a series of if condition statements, but if one block of if condition statement writes the log to the file , the subsequent block of if condition... (7 Replies)
Discussion started by: ananan
7 Replies

3. UNIX for Dummies Questions & Answers

little problem of file redirection (awk)

I almost reach my objective (Youhouuu !!!!) But I really don't understand why it doesn't work until the end... :wall: For clarity's sake I am taking a very simple example. The operations I am doing in the script (gsub and print) really don't have any importance !!! I just matter about... (10 Replies)
Discussion started by: beca123456
10 Replies

4. Shell Programming and Scripting

Output redirection of c binary file to a file in shell script is failing

I am struck up with a problem and that is with output redirection. I used all the ways for the redirection of the output of c binary to a file, still it is failing. Here are the different ways which I have used: ./a.out | tee -a /root/tmp.txt 2>&1 ./a.out | tee -a /root/tmp.txt 1>&1 ./a.out |... (2 Replies)
Discussion started by: Maya29988
2 Replies

5. Shell Programming and Scripting

output redirection to existing file question

So I have a existing file that I used the uniq command on and I need to save the output to the same file without changing the file name. I have tried $ uniq filename > filename then when I cat the file it then becomes blank like there is nothing inside. any help would be much appreciated... (0 Replies)
Discussion started by: drew211
0 Replies

6. UNIX for Dummies Questions & Answers

Capping output redirection log file length

I am trying to write a script which will output notifications to a logfile, but I would like to cap the logfile to, let's say, 200 lines. Specifically I am using custom firmware, DD-wrt, on my router and I am implementing a script to connect to my work vpn. I have a loop that pings a computer... (2 Replies)
Discussion started by: joemommasfat
2 Replies

7. UNIX for Dummies Questions & Answers

Output file redirection

Suppose I have a file named a When I write cat a>a The following error message is displayed cat: a: input file is output file and my file a is truncated to zero size. Also the exit status of the last command is 1 Can someone tell me what actually happens when I do so? (1 Reply)
Discussion started by: aagajaba
1 Replies

8. Shell Programming and Scripting

Remote server file output redirection

Hi, I want ssh to the remote server and then execute ls and redirect the output to the file in remote server itself like ssh root@$server `ls /var/log/users.txt > root@$server:/home/users.txt` Can you please let me know the correct syntax for it. Thanks in advance (2 Replies)
Discussion started by: mohitmoudgil
2 Replies

9. UNIX for Dummies Questions & Answers

Redirection of output to a log file

Apologies for the trivial nature of this question but I cannot seem to get a simple re direct to a log file to work Step 1 touch log.txt at -f batch.sh now >> log.txt I am trying to get the batch.sh contents into the log file Manny Thanks (8 Replies)
Discussion started by: JohnCrump
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