Numbering Lines

Hello everyone,

I want get numbered lines from a file. and i can do it with: sed = file.txt | sed "/./N; s/\n/ /" | sed -n "5,7p"

but the output that i get is something similar to:
5 line5
6 line6
7 line7

and i want something like this (with 2points after the number):
5: line5
6: line6
7: line7

but without using loops to do it, like
for i++
then
echo "i: sed -n "{i}p" file.txt"
end

I really want avoid loops. i hate them in bash scripts! :mad:

simple write this..

awk '{print NR": "$0}' filename
but one condition it won't check for empty lines..

simply you can use this also... :slight_smile:

whow man!!!

thanks for the fast replay...

this sed = file.txt | sed "/./N; s/\n/: /;5,7p" solved my problem!

-- EDIT --

well, i used a little different approach: sed = file.txt | sed "/./N; s/\n/: /" | sed -n "5,7p". I couldn't use the above commands set...

cat -n filename (won't put ':' but will do the job)

IMO, nl seems to be the easiest, most lightweight choice. cat is up there as well.