How to get evenly Line numbers?

hi there ,

i m new to unix , i d like to ask how can a get only even numbered lines matches with the word i search from txt file

for example :

3461:1.D. The copyright laws of the place where you are located also govern
3471:1.E. Unless you have removed all references to Project Gutenberg:
3473:1.E.1. The following sentence, with active links to, or other immediate
3485:1.E.2. If an individual Project Gutenberg-tm electronic work is derived
3494:1.E.9.
3496:1.E.3. If an individual Project Gutenberg-tm electronic work is posted
3503:1.E.4. Do not unlink or detach or remove the full Project Gutenberg-tm
3507:1.E.5. Do not copy, display, perform, distribute or redistribute this
3513:1.E.6. You may convert to and distribute this work in any binary,
3525:1.E.7. Do not charge a fee for access to, viewing, displaying,
3529:1.E.8. You may charge a reasonable fee for copies of or providing
3562:1.E.9. If you wish to charge a fee or distribute a Project Gutenberg-tm
3569:1.F.
3571:1.F.1. Project Gutenberg volunteers and employees expend considerable

i want to grep (or any other commands ) the evenly number lines such as ;
.
.
.

3496:1.E.3. If an individual Project Gutenberg-tm electronic work is posted
3494:1.E.9.
3562:1.E.9. If you wish to charge a fee or distribute a Project Gutenberg-tm
.
.
.

i hope i m clear enough i tried many regular expressions but didn t work

THE PROBLEM IS PUNCTUATION ( : ) i believe bcus it reads them all as one string that makes it hard to seperate! , there might be other numbers in the line !

i don t know why this doesn t work grep -n '[0-9]*[08]*' list.txt

I'm not 100% sure what you're doing in that regex but remember that * has a slightly different meaning in a regex than it does in shell globbing. In a shell, * means "match zero or more of any character". In a regex it means "match zero or more of the previous character". So [0-8]* tells it to match zero or more characters in the set 0-8. Also, in a regex, . is a special character meaning "any character".

So I think you could do:

grep "...[02468]" filename

which will match anything for the first three chars, then only even numbers for the last digit.

i didn't completely understand what you mean. If you just want to get the lines with even number lines, you could try this:

kent$ seq 10|sed -n 'n;p;'
2
4
6
8
10

if this is what you want, you could

 sed -n 'n;p;' yourfile

ok but point is "i need to get evenly line numbers"

grep "...[02468]" filename

same number mixed string combination can be placed any where in any line

3461:1.D. The copyright laws of the place where you are located also govern

what i need is get the line number 3461 from a line only if it s an even number!

---------- Post updated at 11:59 AM ---------- Previous update was at 11:56 AM ----------

[/CODE]if this is what you want, you could

 sed -n 'n;p;' yourfile

[/quote]

is exactly wht i need , thank u very much bro.

sed -n '/^[0-9]*[02468]:/p' myFile

deleted since misunderstood the requirement.

this can be simplified:

nawk -F: '!$1%2' myFile

great! I didn't even think of the ":" as FS .... stupid...
but anyway this is not what he wanted..

is there any way to make this with grep and some regular exp.

try

grep '^...[02468]' inputfile

i m very sorry that i couldn t explain it good !

ur grep might get other even numbers from the line , but the numbers at the beginnig of lines are the line numbers of a txt file ,in that line there might be other numbers similar to line number so i only want to get the evenly line numbers ,and common point of those numbers in each line is ":" , i tried many regex with ":" in it but didn t work.. like grep '[0-9]*[02468]:' list.txt but didn t work

Post sample input file removing the line numbers and the expected output.

ok , i start from very beginning ;

imagine i have a text with 3700 lines

"You are to write a script that takes a file name and a word as
input. You will then locate all lines within the file ($1) which
contain that word ($2) -- but there is a twist. The word must
appear at the END of the line, but not exactly: there must be a
period after the word.
In other words, you are finding all lines which have the given
word as the last word in a sentence, with this sentence finishing
at the end of the line also.

                    But you are not done. You will filter your above grep results so 
                    that you only consider matches on the evenly number lines."

then i will get the middle line among all of these even numbered matches "

that s the work i have to do , this is the original explanation

what you need to find out ?? 1) Lines with even line number OR 2) Lines containing word(provided as input) at the end of line. OR 3) BOTH

1-) first grep a word but the word u grep must appear at the end of the line (i know this part grep 'word'$)

2-) then You will filter your above grep results so
that you only consider matches on the evenly number lines

3-) Next, you will use ( sed 's_[^0-9].*__' ) to help you to locate the
middle line among all of these even numbered matches. ( this part is easy the program is already given)

4-) Your final result is that you will print this line

So: You end up with the median line among all even-numbered lines
that match to your word as the last word of its line & sentence.

Is this a homework assignment?

This should do the trick in one grep command

word="posted"
grep -E "^[^:]*[02468]:.*${word}$" yourfile.txt

But as Franklin52 stated, if this is part of an home assignment you should have posted it on the right forum Homework & Coursework Questions - The UNIX and Linux Forums

is an example question from internet reference book!