[Discuss] sed question

Alan W. Irwin irwin at beluga.phys.uvic.ca
Wed May 21 10:42:27 PDT 2008


On 2008-05-21 10:33-0700 pw wrote:

> Hello,
>
> Is there a way to use sed to remove all non-alphanumeric
> characters from a file.
>
> ie:
>
> sed -e "s/![a-zA-Z]&![0-9]/\ /g"

I am not sure about the above complicated syntax, but the following more
simplified syntax works for me on a file I happened to have lying around.

irwin at raven> head test.data
zlib.dll.a[dt.o]: .bss b 00000000
zlib.dll.a[dt.o]: .data d 00000000
zlib.dll.a[dt.o]: .idata$4 i 00000000
zlib.dll.a[dt.o]: .idata$5 i 00000000
zlib.dll.a[dt.o]: .idata$7 i 00000000
zlib.dll.a[dt.o]: .text t 00000000
zlib.dll.a[dt.o]: __zlib_dll_a_iname I 00000000
zlib.dll.a[dh.o]: .bss b 00000000
zlib.dll.a[dh.o]: .data d 00000000
zlib.dll.a[dh.o]: .idata$2 i 00000000


irwin at raven> sed "s/[a-zA-Z0-9]//g" test.data |head
..[.]: . 
..[.]: . 
..[.]: .$ 
..[.]: .$ 
..[.]: .$ 
..[.]: . 
..[.]: _____ 
..[.]: . 
..[.]: . 
..[.]: .$


Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the Discuss mailing list