[lug] Stripping whitespace in a shell script
rm at fabula.de
rm at fabula.de
Wed Feb 20 10:25:59 MST 2002
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
> -----Original Message-----
> From: Chip Atkinson [mailto:chip at rmpg.org]
> Sent: Wednesday, February 20, 2002 9:55 AM
> To: 'lug at lug.boulder.co.us'
> Subject: Re: [lug] Stripping whitespace in a shell script
>
>
> You could use sed. For example,
> sed -e "s/ *$//"
> This works in the test that I just ran.
>
> Chip
>
> On Wed, 20 Feb 2002, Riggs, Rob wrote:
>
> > I'm looking for an effecient way to strip whitespace from the trailing end
> > of a line of text in a shell script.
> >
> > I was using "awk '{print $1}'", but it breaks down when there is embedded
> > whitespace in the text, spitting out only the portion prior to the first
> > embedded whitespace. While whitespace should not be embedded, it occurs
> > frequently enough that I need to deal with it.
> >
> > Any suggestions on how to do it in Bash script?
> >
> > -Rob
> >
> >
> > _______________________________________________
> > Web Page: http://lug.boulder.co.us
> > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> >
>
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
More information about the LUG
mailing list