in reply to search and replace with serialized answers

#!/usr/bin/perl use strict; open (INFILE, "$ARGV[0]"); my @lines = <INFILE>; close (INFILE); my $responses = 0; foreach (@lines) { if ($responses < $ARGV[1]) { $responses++ } else { $responses = 1; } chomp $lines[$_]; print $lines[$_] . $responses . "\n" }

input.txt

test test test test test test test test test test test

Called as:

{C} > test input.txt test1 test1 test1 test1 test1 test1 test1 test1 test1 test1 test1 {C} > test input.txt 5 test1 test2 test3 test4 test5 test1 test2 test3 test4 test5 test1

Replies are listed 'Best First'.
Re^2: search and replace with serialized answers
by TheBigAmbulance (Acolyte) on May 01, 2009 at 19:23 UTC
    That's great.  I'm on the right path.  Let me throw in another curve.

    Let's say my input file is as follows:

    jack test is a good boy
    jill test is a good boy
    john test is a good boy
    mary test is a good boy
    paul test is a good boy
    link test is a good boy
    karl test is a good boy

    Using a simliar script, how would i have it sniff out the text "test" and then serialize the response per the same type of scheme inputing the number of times I want to serialize it?  Let's say I want to use 5 times so the results would be:

    jack test1 is a good boy
    jill test2 is a good boy
    john test3 is a good boy
    mary test4 is a good boy
    paul test5 is a good boy
    link test1 is a good boy
    karl test2 is a good boy

      and what have you tried in order to reach your goal ? please show us so we can direct you on 'the right path'. have you tried modifying the example VinsWorldcom gave ? what was your conclusion and what difficulty did you encounter ?

      I think you should get a Perl book(maybe this one) and try to read it