Piping through grep/awk prevents file write


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Piping through grep/awk prevents file write
# 1  
Old 03-22-2014
Piping through grep/awk prevents file write

So, this is weird... I'm running this command:

Code:
iotop -o -P -k -bt -d 5

I'd like to save the output relelvant to rsyslogd to a file, so I do this:

Code:
iotop -o -P -k -bt -d 5 | grep rsyslogd >> /var/log/rsyslogd

Nothing is written to the file! I can write the full output to the file:

Code:
iotop -o -P -k -bt -d 5 >> /var/log/rsyslogd

But I can't pipe the output through grep and then write to a file! How odd. I've also tried awk in place of grep. Any idea what might be causing this? Thanks.
# 2  
Old 03-22-2014
My first guess would be stream buffering.

With grep, see if your implementation supports any buffering options (I believe GNU grep does).

With awk, see if it supports fflush(). If it does, call it after each print.

Regards,
Alister
# 3  
Old 03-22-2014
If there are no command line options available with your particular awk or grep, you could use:
Code:
iotop -o -P -k -bt -d 5 |
while IFS= read -r line
do
  case $line in 
    (*rsyslogd*) printf "%s\n" "$line"
  esac
done >> /var/log/rsyslogd

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Piping to grep with pbpaste

cat file 1 aaa 2 bbb 3 ccc 4 ddd In TextEdit, I then copy the characters “ccc” to the clipboard. The problem is that the following command gives no output: bash-3.2$ pbpaste | grep - file Desired output: 3 ccc What should the syntax be for that command? I am using MacOS El... (3 Replies)
Discussion started by: palex
3 Replies

2. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

3. Shell Programming and Scripting

piping from grep to awk without intermediate files

I am trying to extract the file names alone, for example "TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv", from below output which was given by the grep. sam:/data/log: grep "C10_Subscribe.000|subscribe|newfile|" PDEWG511_TVLI_JOB_STATS.ksh.201202* Output: ... (6 Replies)
Discussion started by: siteregsam
6 Replies

4. Ubuntu

Piping with grep

Hi everybody, I have a big file with blast results (if you know what this means, otherwise look at it just as a text file with a specific form). I am trying to extract some ids from within this file, which have certain parameters. For example, some Of my IDs have the term 'No hit results'... (6 Replies)
Discussion started by: frymor
6 Replies

5. Ubuntu

Piping with grep

Hi everybody, I have a big file with blast results (if you know what this means, otherwise look at it just as a text file with a specific form). I am trying to extract some ids from within this file, which have certain parameters. For example, some Of my IDs have the term 'No hit results'... (1 Reply)
Discussion started by: frymor
1 Replies

6. UNIX for Dummies Questions & Answers

Write to file using tail -f through a pipe to grep

Hi -- I'm looking to write to a file after piping output from tail -f through to grep: #write to a file for all lines with "searchtext" within in error_log: Expand|Select|Wrap|Line Numbers tail -f /var/error_log | grep searchtext > output.txt The above command... (2 Replies)
Discussion started by: ndedhia1
2 Replies

7. Shell Programming and Scripting

awk & grep - check for a value and write sub-word

Hi people, I have a file status.txt: Following 6 ports are totally or partially unavailable: ------------------------------------------------------------ MOD LINK PORTNAMES STAT1 STAT2 STAT3 SYN TYPE ------------------------------------------------------------ 8 Pr37 ... (12 Replies)
Discussion started by: gc_sw
12 Replies

8. Shell Programming and Scripting

grep a pattern and replace a value in it and write to the same file.

I have some complication with this, I have a file like below for DEV_1 till DEV_10. and the db values are set accordinly which are not unique. For example DEV1,DEV4,DEV6 can have the same target DB name. I waned to identify for DEV_2 and then replace the TARGET_DATABASE value with the new DB... (6 Replies)
Discussion started by: yesmani
6 Replies

9. Shell Programming and Scripting

Piping tail to awk to parse a log file

Hello all, I've got what I'm pretty sure is a simple problem, but I just can't seem to work past it. I'm trying to use awk to pretty up a log file, and calculate a percentage. The log file looks like this: # tail strtovrUsage 20090531-18:15:45 RSreq - 24, RSsuc - 24, RSrun - 78, RSerr -... (4 Replies)
Discussion started by: DeCoTwc
4 Replies

10. UNIX for Dummies Questions & Answers

Piping GREP

Hi, I need to use a double grep so to speak. I need to grep for a particular item say BOB and then for each successful result I need to grep for another item say SMITH. I tried grep "BOB" filename | grep "SMITH" but it does not seem to work. I can achieve my desired result using an... (12 Replies)
Discussion started by: mojoman
12 Replies
Login or Register to Ask a Question