how to print out line numbers of a text file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to print out line numbers of a text file?
# 1  
Old 12-12-2005
how to print out line numbers of a text file?

i have this text file name test.txt which contain :
aaaaa bbb
iiiiiiiiiiiii ccf
ddaaa ddd

and i need a script that can print out the line numbers using a while loop..
so when the script is run..it will have this:
1
2
3

any ideas? Smilie thanks guys
# 2  
Old 12-12-2005
I think the below sed command will help you

sed -n '=' datafile
# 3  
Old 12-12-2005
thanks again for great help! solve part of my problem already..thanks...
# 4  
Old 12-12-2005
cat -n <filename>|awk '{print $1}'

should help
# 5  
Old 12-12-2005
thanks very much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add line numbers (multiples of 5: 0,5,10,15,20) to a text file?

Hi, I need to number the lines in my text file. I know how to do this with standard numbering (1,2,3,4, etc) but I need to count in multiples of 5, beginning 0,5,10,15... example existing file: abcd efg hijklm nopqrs desired output 0 abcd 5 efg 10 hijklm 15 ... (11 Replies)
Discussion started by: livbaddeley
11 Replies

2. Programming

Read text from file and print each character in separate line

performing this code to read from file and print each character in separate line works well with ASCII encoded text void preprocess_file (FILE *fp) { int cc; for (;;) { cc = getc (fp); if (cc == EOF) break; printf ("%c\n", cc); } } int main(int... (1 Reply)
Discussion started by: khaled79
1 Replies

3. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

4. UNIX for Dummies Questions & Answers

Print numbers and associated text belonging to an interval of numbers

##### (0 Replies)
Discussion started by: lucasvs
0 Replies

5. UNIX for Dummies Questions & Answers

how to print out consecutive two line from a text file

the text file like below's input: aaaaaaaaafdsfsda sdfsadfasdfasfds sdfadsf asdfadf asdfa adfsfsafas sdfsfafads asdfasdfsa I want to print out consecutive two line output: aaaaaaaaafdsfsda (1 Reply)
Discussion started by: vincent_W
1 Replies

6. Shell Programming and Scripting

How to find and print the last word of each line from a text file

Can any one help us in finding the the last word of each line from a text file and print it. eg: 1st --> aaa bbbb cccc dddd eeee ffff ee 2nd --> aab ered er fdf ere ww ww f the o/p should be a below. ee f (1 Reply)
Discussion started by: naveen_sangam
1 Replies

7. Shell Programming and Scripting

Unix help to find blank lines in a file and print numbers on that line

Hi, I would like to know how to solve one of my problems using expert unix commands. I have a file with occasional blank lines; for example; dertu frthu fghtu frtty frtgy frgtui frgtu ghrye frhutp frjuf I need to edit the file so that the file looks like this; (10 Replies)
Discussion started by: Lucky Ali
10 Replies

8. Shell Programming and Scripting

how to add line numbers in text file

Hi all How to add line numbers in text file.. ex abcd cdef result 1. abcd 2. cdef thx in advance (4 Replies)
Discussion started by: suryanarayana
4 Replies

9. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

10. Shell Programming and Scripting

How to print the lines after 2nd line from text file

Hi All, I need to print the lines after 2nd line irrespective of the number of lines in file if the file contents are like below ---------- root:!:0:0::/root:/usr/bin/ksh daemon:!:1:1::/etc: bin:!:2:2::/bin: sys:!:3:3::/usr/sys: adm:!:4:4::/var/adm: uucp:!:5:5::/usr/lib/uucp:... (6 Replies)
Discussion started by: ram1729
6 Replies
Login or Register to Ask a Question