[lug] Stripping whitespace in a shell script

Chip Atkinson chip at rmpg.org
Wed Feb 20 09:55:10 MST 2002


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
>




More information about the LUG mailing list