in reply to String Search/Replace

Zillion? How about only one:
perl -ple "@f=split; for(@f[1..4]){ $_=0 if $_>1000 } $_=qq{@f}" infil +e >outfile
or in-place:
perl -i.bak -ple "@f=split; for(@f[1..4]){ $_=0 if $_>1000 } $_=qq{@f} +" file
Update:

Better yet, -a saves us the trouble of splitting:

perl -lape "for(@F[1..4]){ $_=0 if $_>1000 } $_=qq{@F}" infile >outfil +e
or in-place:
perl -i.bak -lape "for(@F[1..4]){ $_=0 if $_>1000 } $_=qq{@F}" file

perlrun documents -i, -l, -a, -p and -e.

The command can be written in fewer strokes, but I left it readable.

Replies are listed 'Best First'.
Re^2: String Search/Replace
by crep (Novice) on Aug 31, 2005 at 14:40 UTC
    Hm... I tried the first in your original post and your updated, both give the same error. I check, and the file I'm using is definatly writable.
    bash-2.05$ perl -ple "@f=split; for (@f[1..4]) { $_=1000 if $_>1000; } + $_=join(' ',@f)" TEST Can't modify constant item in scalar assignment at -e line 1, near "10 +00 if" Execution of -e aborted due to compilation errors. bash-2.05$ perl -lape "for(@F[1..4]){ $_=1000 if $_>1000 } $_=qq{@F}" +TEST Can't modify constant item in scalar assignment at -e line 1, near "10 +00 if" Execution of -e aborted due to compilation errors.
    Did I do something wrong?

    -Jack C
    jack {@} crepinc.com
    http://www.crepinc.com/

      I'm using quoting appropriate for the Windows shell. Substitute " for ' and vice-versa for unix shells.
        Ahh ok thanks!

        -Jack C
        jack {@} crepinc.com