Hello Brothers and Sisters. I am trying to write a script to change change 100's of files. Change a line if it exists or add it if it doesn't exist. I'm having multiple issues. I thought I would grep to see which files don't have the line. Then from that array add the line. all the rest just switch the line. I'm having problems with grep I'm reading in a list of files. I want to grep which files have the line with bgs in it. Replace that line with the new line which is the new way to start Best1. Many of the files don't have the line. So, for the files that don't have it. I need to add it. Then, I am going to open another file and do some more stuff to that. So, some of this code may not make sense. THANK You!
#!/usr/bin/perl -w use strict; open CF_FILES, "cf.files" or die "Error: $!"; my @cf_files=<CF_FILES>; close CF_FILES; foreach my $cf(@cf_files){ open CF, $cf my @AR =<CF>; my @L = grep( /bgs/, @AR); print @L; } ;
Thanks

In reply to grep question by wcj75019

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.