Re: [SLUG] need a command

From: Daniel MacLaren (daniel-slug@creag.org)
Date: Wed Apr 07 2004 - 10:11:01 EDT


On Wed, 7 Apr 2004, Ronan Heffernan wrote:

> Levi Bard wrote:
>
> >>I need to rid a numeric file of all lines that contain non-numeric
> >>characters ie [0-9]. In other words I only want numbers in that file.
> >>I think I recall seeing a sed statement that deleted anything except
> >>0-9. I just don't recall the systax.
> >>I have tried the ! thinking it would do the trick but it does not.
> >>Can anyone help me with this?
> >>
> >>
> >
> >grep -v '[0-9]' file
> >
> >
> No, that will give all of the lines that do contain numbers (but the
> output will include the non-numeric characters. Try:
>
> sed "s/[^0-9]//g" filename
>
> --ronan
>

That will remove all non-numeric characters, but he said he wanted to
remove the line containing non-numeric characters.

This will send output to stdout:

sed "/[^0-9]/d" <filename>

To edit the file in place:

sed -i "/[^0-9]/d" <filename>

To remove the lines from the file and create a backup of the
original called filename.bak:

sed -i.bak "/[^0-9]/d" <filename>

-Daniel

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:14:29 EDT