Apr 23, 2003 #1 6656 Programmer Nov 5, 2002 104 US Hi, anyone can give me an example in ksh that How to add line numbers to a file or print a file with line numbers? Thanks, Mike
Hi, anyone can give me an example in ksh that How to add line numbers to a file or print a file with line numbers? Thanks, Mike
Apr 23, 2003 1 #2 vgersh99 Programmer Jul 27, 2000 2,146 US man nl vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+ Upvote 0 Downvote
Apr 23, 2003 1 #3 CaKiwi Programmer Apr 8, 2001 1,294 US Or cat -n CaKiwi "I love mankind, it's people I can't stand" - Linus Van Pelt Upvote 0 Downvote
Apr 23, 2003 1 #4 olded Programmer Oct 27, 1998 1,065 US How about the print files command: pr -n Ed Upvote 0 Downvote
Apr 23, 2003 1 #5 tdatgod Programmer Jul 21, 2001 601 US All the good answers have been taken. awk '{printf("%8d %s\n", NR,$0)}' file --- Upvote 0 Downvote
Apr 23, 2003 #6 bigoldbulldog Programmer Feb 26, 2002 286 US And also, sed = file | sed 'N;s/\n/ /' Has this been done in pure ksh yet? Cheers, ND bigoldbulldog@hotmail.com Upvote 0 Downvote
And also, sed = file | sed 'N;s/\n/ /' Has this been done in pure ksh yet? Cheers, ND bigoldbulldog@hotmail.com
Apr 23, 2003 #7 vgersh99 Programmer Jul 27, 2000 2,146 US not yet: sed = file.txt | sed 'N;s/\n/ /' Upvote 0 Downvote
Apr 23, 2003 #8 olded Programmer Oct 27, 1998 1,065 US With a nod towards tdatgod's solution: #!/bin/ksh lineno=0 OIFS=IFS while IFS="&" read -r txtline; do IFS=OIFS lineno=$((lineno+1)) printf "%8d %s\n" $lineno $txtline OIFS=IFS done < d.file You probably want to use something other than "&" as a field separator. What a hastle! Regards, Ed Upvote 0 Downvote
With a nod towards tdatgod's solution: #!/bin/ksh lineno=0 OIFS=IFS while IFS="&" read -r txtline; do IFS=OIFS lineno=$((lineno+1)) printf "%8d %s\n" $lineno $txtline OIFS=IFS done < d.file You probably want to use something other than "&" as a field separator. What a hastle! Regards, Ed
Apr 23, 2003 #9 vgersh99 Programmer Jul 27, 2000 2,146 US modifying a bit olded idea: #!/bin/ksh lineno=0 while txtline=$(line); do lineno=$((lineno+1)) printf "%8d %s\n" "$lineno" "$txtline" done < $1 vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+ Upvote 0 Downvote
modifying a bit olded idea: #!/bin/ksh lineno=0 while txtline=$(line); do lineno=$((lineno+1)) printf "%8d %s\n" "$lineno" "$txtline" done < $1 vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+
Apr 23, 2003 #11 SamBones Programmer Aug 8, 2002 3,186 US Borrowing from vlad and going for the Brevety Award... Code: #!/bin/ksh lineno=0 while txtline=$(line); do print "$((lineno += 1)) $txtline"; done < $1 Upvote 0 Downvote
Borrowing from vlad and going for the Brevety Award... Code: #!/bin/ksh lineno=0 while txtline=$(line); do print "$((lineno += 1)) $txtline"; done < $1