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.
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
"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
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.