I'm looking to tail a file while ignoring 3 different strings and the line under them


Staff member
Oct 27, 2011
Reaction score
So, i have a domain name querying script.. it generates 4 char strings, then adds .com to the end and does a whois on them. When whois returns 0, it prints 'blah.com: available' in a text file (/tmp/list.txt).

So, while this is running, i'm tailing /tmp/list.txt.. I also have stderr going there because I get a few different errors during the runtime:
fgets: Connection reset by peer
connect: Network is unreachable

The /tmp/list.txt file will look something like this:
ohlm.com available
iuqr.com available
blah.com available
fgets:Connection reset by peer
blah2.com available
negd.com available
fhjj.com available

I don't want to see the errors or the line underneath them because it returns true, saying they're available when they actually aren't.

I came up with this so far:

tail -f /tmp/list.txt|sed '/Timeout/,+1d'
which hides the Timeout line along w/ the one underneath it, but how can I add the fgets and unreachable strings matches to it?

I know I can use grep -v to hide a string, but I don't believe I can add an A to strip out the line under it..

@JasKinasis and @dos2unix i'm looking at you guys! lol

Edit: here's the scripts involved .. to make it easier to understand... i'll fire it off by running the domain-search.sh script.


touch /tmp/list.txt
while true; do /usr/local/bin/check-avail.sh $(cat /dev/urandom | tr -dc 'a-z' | fold -w 4 | head -n 1) >> /tmp/list.txt 2>&1;sleep 20;done &
#while true; do /usr/local/bin/check-avail.sh $(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1) >> /tmp/list.txt;sleep 20;done &
#for i in $(sort --random-sort /usr/local/bin/word_list.txt);do /usr/local/bin/check-avail.sh $i >> /tmp/list.txt 2>&1;sleep 20;done &

#for domain in com net info org pro; do
for domain in com; do
    if ! whois ${1}.$domain >> /dev/null; then
        echo "${1}.$domain available"
Last edited:

ohhh.. just thought of another option.. it'd be better if i could grep out the stderr along w/ it's next line before it goes into the file? No idea on that one though.

One day i'd like to combine the two scripts, but I haven't thought that far ahead :)
Last edited:
You could possibly use egrep.

tail somefile.txt | egrep -v 'Timeout|fgets|Network'

which is basically what your sed script does.
  • Like
Reactions: Rob
I’ve only just seen this post.
I’ll take a more detailed look when I’m at work tomorrow, either during a long debug build, or during my lunch break.

Sed sounds like an idea, but I'm not sure how you'd go about ignoring the line after a match.

If it's beyond the capabilities of sed, then perhaps either an awk script, or maybe a Python or Perl script?
Hang on! Taking a more detailed look at this thread - that sed command you've posted a few posts above does exactly what you want doesn't it?

That will strip out the matching line, plus one extra line...
Well, that saved my thinker a lot of work! You've already solved it! :D
Last edited:

Members online

Latest posts