On Mon, Dec 29, 2008 at 17:14, John W. Krahn <jwkr...@shaw.ca> wrote: > John W. Krahn wrote: >> >> blackd77 wrote: >>> >>> Hello. I want to add sequential numbers to a file, one number per >>> line, at the end of each line. The files have a .csv format. So, I'd >>> like to add ",1" to the first line, ",2" to the second line, and so on >>> (without the quotation marks of course). I have not started building >>> the code, so there isn't anything to critique yet. I'm just thinking >>> about how to start, so anything that would point me in the right >>> direction would be helpful and welcome. >>> >>> I have thought about something that would combine the pushing of a >>> value to an array, with some kind of auto-increment routine. Set a >>> scalar to 1, read line one, split on the commas, push the value onto >>> the array, increment 1 to 2, move to line two, read line two, split on >>> the commas, push the value onto the array, increment 2 to 3, move to >>> line three, etc... >>> >>> Any suggestions will be helpful. I'll be trying to put a routine >>> together tomorrow morning. This is probably really simple for the >>> experts. >> >> perl -pe's/$/",".++$a/e' yourfile > > perl -pe's/$/,$./' yourfile snip
This one handles multiple files: perl -pe '$.=1 && $o=$ARGV unless $o eq $ARGV; s/$/,$./' file1 file2 -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/