Message from discussion
Writing a line based filter that exits when no input
Path: g2news1.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news.glorb.com!news2.glorb.com!de-l.enfer-du-nord.net!gegeweb.org!aioe.org!not-for-mail
From: Anand Hariharan <znvygb.nanaq.unevun...@tznvy.pbz>
Newsgroups: comp.unix.programmer
Subject: Writing a line based filter that exits when no input
Date: Sat, 4 Jul 2009 06:10:12 +0000 (UTC)
Organization: Aioe.org NNTP Server
Lines: 27
Message-ID: <pan.2009.07.04.06.09.58@tznvy.pbz>
Reply-To: "Anand Hariharan" <mailto.anand.hariha...@gmail.com>
NNTP-Posting-Host: 8cgrpkho4TffePGKbdqTYw.user.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@aioe.org
X-Notice: Filtered by postfilter v. 0.7.9
X-Face: R$62aNc~s?NZjz<3:iK:?J_Nc}\>C9KRI(A|(4TZMn`Er<8Nk~UD=N*+~IQ;?%T5%.8xH!WSAg=02[J2O%=gg:mD,g]K6fc#=|5=&>1;(v.Gin3'.a1yw'a\>?hl=[d;I~U?s|yK'XtbJJ5Tkc~zR#Lj(RAt[%QJYiy%zULO!SR^5!&"ee5GgQWE[Gf=8SaF5`c2z%7-2
Cancel-Lock: sha1:iCm8ygxUqAVOWiggryjIFwymLjE=
Am writing a line-based filter a la sed or tr. What I would like it to
do, however, is if there is no input at start-up, it should present some
usage information and exit.
E.g.,
$ MyLineFilter < TextFile # OK
$ Some Command | MyLineFilter # OK
$ MyLineFilter
MyLineFilter: Did not find any text to process. Exiting.
$ echo $?
1
$ MyLineFilter Command Line Args # Undecided what to do here ...
Would appreciate some ideas on how to implement this.
Currently, am writing the usage information to stderr (unconditionally),
but the executable waits for input until it finds EOF.
thanks,
- Anand