in reply to search and replace on a line by line basis

Does:
perl -lne 'next if /.{188}00000000.{16}/; $d='20020101'; s/(.{188})\d{ +8}(.{16})/$1$d$2/; print' original.txt > new.txt
do what you need?

Replies are listed 'Best First'.
Re: Re: search and replace on a line by line basis
by pizza_milkshake (Monk) on Apr 15, 2004 at 17:39 UTC
    that assumes that all lines in the file are of the format he describes. your example will pass through blank lines, for example. i believe he wants anything that is invalid filtered.

    perl -e'$_="nwdd\x7F^n\x7Flm{{llql0}qs\x14";s/./chr(ord$&^30)/ge;print'

      Good point.

      How about:

      perl -lne 'next if /^.{188}0{8}.{16}$/; print if s/^(.{188})\d{8}(. +{16})$/${1}20020101$2/' original.txt > new.txt