ׁHi Charith, On Fri, 2 Sep 2011 20:42:31 -0700 (PDT) Charith LokuBogahawatta <charith...@gmail.com> wrote:
> Hi All, > > I'm new to this group also for perl but nowadays I working around with > Perl and I need some help. this my first thread please anyone can help > me? > > i have a file contains the following data. > > charith 4 matara > saman 8 kandy > andrew 9 colombo > dilshan 3 galle > shanil 10 jafna > . > . > . > Here I want to replace second column (Number) with incremental number > sequence. output should be following. > > charith 0 matara > saman 1 kandy > andrew 2 colombo > dilshan 3 galle > shanil 4 jafna > . > . > . You can do it from the command line like: shlomif@lap:~$ cat test.txt charith 4 matara saman 8 kandy andrew 9 colombo dilshan 3 galle shanil 10 jafna shlomif@lap:~$ perl -lan -e '$F[1] = ($counter++); print "@F";' test.txt charith 0 matara saman 1 kandy andrew 2 colombo dilshan 3 galle shanil 4 jafna shlomif@lap:~$ Note that the '...' delimiters won't work on Microsoft Windows, and you'll need to use "..." instead. See http://perldoc.perl.org/perlrun.html for more explanation on what I did here. You can also use the -i flag (also from perlrun) to edit the file in-place. Regards, Shlomi Fish > > Thank you very much > > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/ “We’re not doing it for money… we’re doing it for a shitload of money!” — Spaceballs, http://www.imdb.com/title/tt0094012/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/