[SGVLUG] Shell fun: cutting the last field of a record...

Bryan D Howard bryan at jetcafe.org
Fri Mar 24 12:51:20 PST 2006


"Emerson, Tom" <Tom.Emerson at wbconsultant.com> writes:
>    filea
>    fileb
>    filec\015

Interesting.  That matches the output of 'ls -1b' on my Solaris box.
On my linux box (FC4 ppc), it looks like this:

    $ ls -1b
    filea
    fileb
    filec\r

> how can I eliminate that trailing "/r" ?  (and before you ask, the
> workfile is being generated by a database extract of fields that were
> populated by a [visual] spreadsheet-style database query tool, so
> inadvertantly pressing <enter> during data entry could easily go
> unnoticed)

You can run the string through tr(1) to remove any characters you
don't want.  And you can either specify a list to get rid of:

    $ echo $whatever | tr -d "\015"

or list to keep:

    $ echo $whatever | tr -cd a-zA-Z0-9

{Bryan}
-- 
Bryan D Howard
<bryan at alumni.caltech.edu>


More information about the SGVLUG mailing list