Quantcast
Channel: Write a program that read from a file and print the line with line number - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 4

Write a program that read from a file and print the line with line number

0
0

I need to write a program that will read line from a file and then output the lines.

So the files contains this:

This is the first line
This is the second line
This is the third line

This was a blank line

The output should be this:

1. This is the first line
2. This is the second line
3. This is the third line
4.
5. This was a blank line

I know I can do:

nl -b a tst16

But this doesn't print the "." after the numbers plus I want to know if there is a way to do this is like a loop or something.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images