How to get evenly Line numbers?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get evenly Line numbers?
# 8  
Old 03-16-2011
great! I didn't even think of the ":" as FS .... stupid...
but anyway this is not what he wanted..
# 9  
Old 03-17-2011
Quote:
Originally Posted by sk1418
i didn't completely understand what you mean. If you just want to get the lines with even number lines, you could try this:
Code:
kent$ seq 10|sed -n 'n;p;'
2
4
6
8
10

if this is what you want, you could
Code:
 sed -n 'n;p;' yourfile

is there any way to make this with grep and some regular exp.
# 10  
Old 03-17-2011
try
Code:
grep '^...[02468]' inputfile

# 11  
Old 03-17-2011
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
# 12  
Old 03-17-2011
Post sample input file removing the line numbers and the expected output.
# 13  
Old 03-17-2011
Quote:
Originally Posted by michaelrozar17
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
# 14  
Old 03-17-2011
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

VI editior line numbers

Hello All, I am very sure this a dumb question to many, but from my view its worth asking. When I do a vi on a file, on the right bottom side I am seeing something like below: 27,16-24 7% which tells me that I am on line 27 (which is the first number before the comma, i would like... (11 Replies)
Discussion started by: babyPen1985
11 Replies

2. Shell Programming and Scripting

Start the line only with numbers

hi, I need some unix command to replace the following thing. The line shuld start with oly numbers. If it starts with anything other than number it shuld be taken back to the last line. My file: 1234|test weye|test1|break 576|test|break|title 2369|test|line|break tite|break... (7 Replies)
Discussion started by: anshaa
7 Replies

3. Shell Programming and Scripting

Assign Line Numbers to each line of the file

Hi! I'm trying to assign line numbers to each line of the file for example consider the following.. The contents of the input file are hello how are you? I'm fine. How about you? I'm trying to get the following output.. 1 hello how are you? 2 I'm fine. 3 How about you? ... (8 Replies)
Discussion started by: abk07
8 Replies

4. UNIX for Dummies Questions & Answers

grep to get line numbers

I know if i use grep -n that the output will have the lines numbered but is there a way to grep the actually line number. so like this grep -n "one" /usr/dict/numbers 1:one 21:twenty-one 31:thirty-one 41:forty-one 51:fifty-one 61:sixty-one 71:seventy-one 81:eighty-one 91:ninety-one ... (1 Reply)
Discussion started by: alindner
1 Replies

5. Shell Programming and Scripting

More with line numbers

Hi All, How to get line numbers when we more on a file in LINUX thanks firestar (1 Reply)
Discussion started by: firestar
1 Replies

6. Shell Programming and Scripting

Removing Line numbers

Hi all, I have a file consisting of lines in such a format: separated by space and M1 EOS for fullstop (.) ] e.g M1 I M1 have M1 a M1 file M1 consisting M1 of M1 lines M1 in M1 such M1 a M1 format M1 EOS M2 This M2 is M3 an (4 Replies)
Discussion started by: my_Perl
4 Replies

7. Shell Programming and Scripting

Display Line numbers

Hi all experts, I am getting error in my shell scripts and i want to find out which lines is in errors. How i can display the line numbers . Is it NU command? Please give me some suggestions. (4 Replies)
Discussion started by: ma466
4 Replies

8. UNIX for Advanced & Expert Users

Add line numbers to end of each line

Hi i would like to add line numbers to end of each line in a file. I am able to do it in the front of each line using sed, but not able to add at the end of the file. Can anyone suggest The following code adds line number to start of each line sed = filename | sed 'N;s/\n/\t/' how can i... (5 Replies)
Discussion started by: rudoraj
5 Replies

9. Shell Programming and Scripting

add line numbers

Hello.. I have got one file ... I want to add line numbers with space form starting to ending.. for example...if the file is -------------------------- sand sorcd 2345 345 recds 234 234 5687 yeres 568 988 erfg4 67 -------------------------- I need the output ... (4 Replies)
Discussion started by: esham
4 Replies

10. UNIX for Dummies Questions & Answers

Printing line numbers

Maybe this question is out there, but I searched and didnt see it. To print my files I use more filename | lpr -Pprinter I would like to print my scripts with line numbers. How do I do this? (2 Replies)
Discussion started by: MizzGail
2 Replies
Login or Register to Ask a Question