[lug] Stripping whitespace in a shell script

rm at fabula.de rm at fabula.de
Wed Feb 20 10:36:26 MST 2002


On Wed, Feb 20, 2002 at 10:16:37AM -0700, Scott A. Herod wrote:
> Won't [:space:] also do it?

I woundered myself. From the manpage:

Regular expressions
       POSIX.2  BREs  should  be  supported, but they aren't com­
       pletely yet.  The \n  sequence  in  a  regular  expression
       matches  the  newline  character.  There are also some GNU
       extensions.  [XXX FIXME: more needs to be  said.   At  the
       very   least,   a  reference  to  another  document  which
       describes what is supported should be given.]

Hmm, where does this leave us? I was simply too lazy to check ;-)
BTW, '[:space:]' is probably locale-dependant, something i _really_
try to avoid in shell scripting (bitten once too often).

Oh, from sysadmin hell: a friend of mine called me yesterday in
emergency state: he did modify his bind configuration and everything
stopped working. After about an hour of fruitless debugging i opened
named.conf with emacs and realized the 'DOS' prompt in the status line ...
It turned out that my friend edited his configuration with MS-Notepad
(no idea why) and bind doesn't like  '\r' :-/ 
So much for whitespace being whitespace ....
 
# Ralf
  
> rm at fabula.de wrote:
> > 
> > On Wed, Feb 20, 2002 at 10:04:46AM -0700, Riggs, Rob wrote:
> > > Thanks Chip. But that sed script will only strip spaces. I'm looking to
> > > strip all whitespace, not just " ", but also newlines, tabs, etc.
> > 
> > How about:
> > 
> >   sed -e 's/[\n\t\r ]*$//'
> > 
> > You can insert all sorts of characters into the '[  ... ]' construct,
> > depending on your dfinition of whitespace.
> > 
> >    Ralf



More information about the LUG mailing list