(e)grep "remove lines with only numbers"

HOwdy --

This is seem like it should be a simple task for grep.
I have a file that looks like this:



\section{Chapter 1}

1
One fish two fish
2 3

Red fish blue fish


What I want to do i remove the line that have numbers on them and nothing else?


TIA,
David
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
lists [ Do, 08 Juli 2004 09:49 ] [ ID #64347 ]

Re: (e)grep "remove lines with only numbers"

lists [at] lastisfirst.com wrote:
> This is seem like it should be a simple task for grep.
> I have a file that looks like this:
>
>
>
> \section{Chapter 1}
>
> 1
> One fish two fish
> 2 3
>
> Red fish blue fish
>
>
> What I want to do i remove the line that have numbers on them and nothing else?

Maybe something like:

egrep -v '^[0-9 ]*[0-9][0-9 ]*$'

?

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
zavandi [ Do, 08 Juli 2004 10:56 ] [ ID #64348 ]

Re: (e)grep "remove lines with only numbers"

Try:
grep -v "^[0-9]*$" file > newfile


> > This is seem like it should be a simple task for grep.
> > I have a file that looks like this:
> >
> >
> >
> > \section{Chapter 1}
> >
> > 1
> > One fish two fish
> > 2 3
> >
> > Red fish blue fish
> >
> >
> > What I want to do i remove the line that have numbers on them and nothing else?

Rudy Vener
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
salt [ Do, 08 Juli 2004 12:03 ] [ ID #64350 ]

Re: (e)grep "remove lines with only numbers"

On Thu, 8 Jul 2004 lists [at] lastisfirst.com wrote:

> HOwdy --
>
> This is seem like it should be a simple task for grep.
> I have a file that looks like this:
>
> \section{Chapter 1}
>
> 1
> One fish two fish
> 2 3
>
> Red fish blue fish
>
>
> What I want to do i remove the line that have numbers on them and
> nothing else?

Assuming that you mean you want to remove the lines that have only numbers
on them, and leave the line that has both numbers and letters, something
like this should work...

egrep -v '^[0-9 ][0-9 ]*$'

In other words, match lines beginning with a number or space, followed by
0 or more numbers or spaces.

This will leave the line with "Chapter 1" in it. If you waant to remove
that too, then all you would need is

egrep -v '[0-9]'

I would strongly recommend getting a copy of "Mastering Regular
Expressions" by Jeffrey E. F. Fredl, and/or checking out
http://sitescooper.org/tao_regexps.html if you want a really good workout
in regular expression creation.

Malcolm


-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Malcolm [ Do, 08 Juli 2004 13:08 ] [ ID #64351 ]

Re: (e)grep "remove lines with only numbers"

M. B. Heath wrote:
> egrep -v '^[0-9 ][0-9 ]*$'

Maybe, but that would also remove the lines containing only spaces...

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
zavandi [ Do, 08 Juli 2004 17:24 ] [ ID #64353 ]

Re: (e)grep "remove lines with only numbers"

This was a quickly thrown together expression to deal with the input
the poster had specified, which didn't have any lines of only spaces.

But you definitely have a point. The one you posted is much better
than mine.

Malcolm

On Jul 8, 2004, at 8:24 AM, zavandi wrote:

> M. B. Heath wrote:
>> egrep -v '^[0-9 ][0-9 ]*$'
>
> Maybe, but that would also remove the lines containing only spaces...
>

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Malcolm Heath [ Do, 08 Juli 2004 18:01 ] [ ID #64354 ]

Re: (e)grep "remove lines with only numbers"

Quoting Malcolm Heath <malcolm [at] indeterminate.net>:

> This was a quickly thrown together expression to deal with the input
> the poster had specified, which didn't have any lines of only spaces.
>
That's to all of you for you suggestions.It did the trick.

Malcolm,
Thanks for the link to the regrex tutorial, I have a look at it.
The book your referring to is from O'Reilly, I actually had that at one point a
couple of years ago.


Thanks again,
David

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
lists [ Do, 08 Juli 2004 20:19 ] [ ID #64356 ]
Linux » gmane.linux.admin » (e)grep "remove lines with only numbers"

Vorheriges Thema: parport_pc problems/strange behavior
Nächstes Thema: ssh tunnel