Grep causing long delay (batching) whilst piping


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep causing long delay (batching) whilst piping
# 8  
Old 07-03-2008
It may be that scheduling has the pipe writer going possibly until the written data gets to PIPE_MAX, or it finishes writing. Then grep reads the the whole pipe contents.

That would account for grep producing a burst of output all with one date.
There is no guarantee for every pipe write there is one pipe read
# 9  
Old 07-03-2008
Quote:
Originally Posted by spudtheimpaler
I appreciate the response, and it's good to know I'm not alone with the problem, but I'm writing this for what could be many boxes, including production servers where perl wont be available. That is of course secondary to the fact that there is already a tool that, as far as I know, should work fine. Apart from your workaround, did you find any information on *why* it might be happening?
I didn't, but I strongly suspect it is optimisation within grep (perhaps one of the most optimised pieces of software on the planet, given its long history and prevalence).

Another portable, if clunky and inefficient, workaround would be to use a shell while/read loop and run grep on each individual line:

Code:
./input.sh | while read line ; do echo "$line" | grep 2008 ; done | ./output.sh

# 10  
Old 07-04-2008
Bug Grep buffering.

It seems that many agree it is buffering, either in the pipes or grep. It seems it only happens in particular combinations as well, e.g. if the ./output.sh is ommited grep doesn't buffer. I suspect the shell is a lot more aware of itself than I had considered, especially in choosing where to buffer.

Thank you all for your help. I appreciate the time and have learnt something.

Cheers again!

Mitch.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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. Solaris

SSH and telnet long delay to recieve prompt.

Hi guys. You'd have to excuse me a bit, as I'm a noob. I really try to avoid asking questions and do research for whatever linux issues that may arise. I am experiencing a long wait for the shell to come up when I ssh or telnet into a Sunos 5.10 environment. It takes 70 seconds to give me... (12 Replies)
Discussion started by: gpenco
12 Replies

3. 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

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. Shell Programming and Scripting

Piping STDOUT as pattern to grep or sed

$>cat file.txt 123 d3 234 abc 3 zyf 23 124 def 8 ghi kz0 ... ... I have the following output on the screen through <some command>. $> <some command> abc def ghi ... ... I have to search for each of these patterns in the file.txt and print the lines in file.txt matching the... (4 Replies)
Discussion started by: VNR
4 Replies

7. 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

8. Shell Programming and Scripting

question about grep, cut, and piping

Howdy folks, I am fairly new to scripting but have lost of expirience in c++, pascal, and a few other. I am trying to complete a file search script that is sent a file name containing data to search that is arranged like this "id","name","rating" "1","bob","7" etc and an argument to... (1 Reply)
Discussion started by: dyrt
1 Replies

9. UNIX for Advanced & Expert Users

Long Delay if any with network services

While installing a firewall, I was pinging the interface from SCO 5.0.6 Openserver box, while no response, I hit "DEL" to cancel, but no cancel. Then all of a sudden I get BOO-KOO traffic lights on HUB and Switch.... Then a kernel trap error. System froze... Proceeded with a cold boot. Now I have... (8 Replies)
Discussion started by: nashvillek5
8 Replies
Login or Register to Ask a Question