Long time parishioner, finally have a problem that my skills don't have, and a search did not provide a solution... You guys are great... Thanks for the anonymous help.

Have a great many text files... All of which have the pesky ^M for EOL, nothing I can do about that (files are created by an outside program).

I need to search each file, find a match, and replace a word that is two lines below.

Example of text:
__TypeOfAirframe__2_0_Cessna152^M
__StartAltitude__2_0_1200^M
__GearStatus__2_0_Down^M

I want to toggle the gear on all Cessna152s.

For clarity... I used _ as space markers. Imagine the above block is repeated 30 or more times, in hundreds of files. TypeOfAirframe is not always a Cessna, so I don't want to toggle the gear on my 747.

I have had great luck with

perl -pi -e 's/find/replace/g' *.txt

But, I cannot get it to recognize the ^M and spaces to perform a search on the above phrase. HELP?


In reply to Find Replace by SimTech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.