Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

enter image description here

Pretend I am working with this file.

The beginning of the first visible line is obscured, so ignore that. 43 is the beginning of the next line, and that line would be deleted.

The next line (which begins with 44 and ends with a period) would be deleted.

The next line (which consists solely of 424) is also gone.

The next line (which consists of '11. King and Hero') is also gone.

The next line stays.

share|improve this question
    
Rather than a screenshot, you should have copy-pasted the sample text as a code block. Think of blind readers! –  Gilles May 21 '11 at 13:01
    
@Gilles I would do that if there was a way to turn off syntax highlighting. (Is there?) –  ixtmixilix May 22 '11 at 7:32
    
You mean the SE syntax highlighting? See SO-specific markup - definitive resource? and in particular Interface options for specifying language prettify: either use <pre> or put <!--language: lang-none--> just before the code block. –  Gilles May 22 '11 at 9:09
    
@Gilles Thanx. I will do that next time. –  ixtmixilix May 22 '11 at 12:59
add comment

3 Answers 3

up vote 6 down vote accepted
sed -e '/^[0-9]/d' filename > filename.new

or to modify in place

sed -i -e '/^[0-9]/d' filename
share|improve this answer
add comment

I'd use grep(1) for this:

grep -v '^[0-9]' filename

^[0-9] matches any line that begins with a digit, and -v excludes the lines that match, instead of including. You can also use the character class [:digit:] instead of [0-9].

Instead of -v you can invert the range:

grep '^[^0-9]' filename

This will match any line that does not start with a digit, but it will not match blank lines.

With grep, sed and awk, my general rule is that for matching and simple extraction, use grep, for stateless re-writing, use sed and for stateful modifications, use awk. That is why I suggest using grep instead of sed as you asked in your question (and others have already answered for sed).

share|improve this answer
    
+1 since I agree this is more a grep work, no need to trouble with sed. I' like to know anyway which gives better performaces (that should matter) –  neurino May 21 '11 at 13:47
add comment
sed -e '/^[0-9].*$/d' oldfile > newfile
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.