<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Matching first line iwth a specific string in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748858#M101636</link>
    <description>Hi Kevin,&lt;BR /&gt;&lt;BR /&gt;I don't know if it'll help at this stage since you may be pursuing a different solution altogether but this awk construct does what you are looking for i.e. encapsulate the header date in the input file.&lt;BR /&gt;&lt;BR /&gt;=================myawk.cmd===================&lt;BR /&gt;{&lt;BR /&gt;    if (prev!=$1$2) {&lt;BR /&gt;        printf("%s %s",b$1,($2&amp;lt;10?" "$2e:$2e))&lt;BR /&gt;        for (i=3;i&amp;lt;=NF;++i)&lt;BR /&gt;            printf(" %s",$i)&lt;BR /&gt;        printf("\n")&lt;BR /&gt;        prev=$1$2&lt;BR /&gt;    } else&lt;BR /&gt;        print $0&lt;BR /&gt;}&lt;BR /&gt;=============================================&lt;BR /&gt;&lt;BR /&gt;Create a file named "myawk.cmd" with the commands above and execute as:&lt;BR /&gt;&lt;BR /&gt;# awk -f myawk.cmd b="&lt;H1&gt;" e="&lt;/H1&gt;" infile&lt;BR /&gt;&lt;BR /&gt;where "b" and "e" are variables containing the characters you want to surround the header date with.&lt;BR /&gt;&lt;BR /&gt;cheers!</description>
    <pubDate>Mon, 13 Mar 2006 20:12:05 GMT</pubDate>
    <dc:creator>Sandman!</dc:creator>
    <dc:date>2006-03-13T20:12:05Z</dc:date>
    <item>
      <title>Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748842#M101620</link>
      <description>Mar 1&lt;BR /&gt;Mar 1&lt;BR /&gt;Mar 2 &lt;BR /&gt;Mar 2&lt;BR /&gt;&lt;BR /&gt;Above is a simplified version of the text I'm processing.&lt;BR /&gt;&lt;BR /&gt;I want to do is surround the Month and Day with a tag "&lt;H1&gt;" and "&lt;/H1&gt;" but only for the first  occurrence.&lt;BR /&gt;&lt;BR /&gt;Below is the command I've tried but it's putting the tags around ALL occurrences of "Mar 1"?&lt;BR /&gt;&lt;BR /&gt;How do I make it just match the 1st occurence?&lt;BR /&gt;&lt;BR /&gt;cat test|sed -e '1,$s/Mar 1/\&lt;H1&gt;&amp;amp;\&amp;lt;\/h1\&amp;gt; /'&lt;BR /&gt;&lt;BR /&gt;========== START OUTPUT======&lt;BR /&gt;&lt;/H1&gt;&lt;H1&gt;Mar 1&lt;/H1&gt; &lt;BR /&gt;&lt;H1&gt;Mar 1&lt;/H1&gt; &lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 2&lt;BR /&gt;========== END OUTPUT======</description>
      <pubDate>Fri, 10 Mar 2006 12:17:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748842#M101620</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2006-03-10T12:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748843#M101621</link>
      <description>Hi Kevin:&lt;BR /&gt;&lt;BR /&gt;# sed -e '1,1s/Mar 1/\&lt;H1&gt;&amp;amp;\&amp;lt;\/h1\&amp;gt; /' file&lt;BR /&gt;&lt;BR /&gt;Note that you don't have to spawn a separate process to first read the file (i.e. the 'cat' piped to 'sed').&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/H1&gt;</description>
      <pubDate>Fri, 10 Mar 2006 12:24:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748843#M101621</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-10T12:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748844#M101622</link>
      <description>Dont use "$", see above&lt;BR /&gt;&lt;BR /&gt;$cat test | sed -e '1s/Mar 1/\&lt;H1&gt;&amp;amp;\&amp;lt;\/h1\&amp;gt; /'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/H1&gt;&lt;H1&gt;Mar 1&lt;/H1&gt;&lt;BR /&gt;Mar 1&lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 2&lt;BR /&gt;</description>
      <pubDate>Fri, 10 Mar 2006 12:26:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748844#M101622</guid>
      <dc:creator>Carlos Roberto Schimidt</dc:creator>
      <dc:date>2006-03-10T12:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748845#M101623</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;For the exact input as in your msg, I'd try the following:&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN {flag=""}&lt;BR /&gt;{if(flag!=$0){print "&lt;H1&gt;",$0,"&lt;/H1&gt;&lt;H1&gt;";flag=$0}&lt;BR /&gt;else print $0}' inputfile&lt;BR /&gt;&lt;BR /&gt;HTH&lt;/H1&gt;</description>
      <pubDate>Fri, 10 Mar 2006 12:28:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748845#M101623</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2006-03-10T12:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748846#M101624</link>
      <description>Kevin,&lt;BR /&gt;&lt;BR /&gt;How about sorting the input first and then piping the result to awk which uses associative arrays for parsing and replacing the string you want.&lt;BR /&gt;&lt;BR /&gt;# sort -k1,2 inp | awk '{if(prev!=$1$2){print b$1,$2e;prev=$1$2}else print $0}' b="&lt;H1&gt;" e="&lt;/H1&gt;"&lt;BR /&gt;&lt;BR /&gt;cheers!</description>
      <pubDate>Fri, 10 Mar 2006 12:59:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748846#M101624</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-03-10T12:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748847#M101625</link>
      <description>Hi (again) Kevin:&lt;BR /&gt;&lt;BR /&gt;It occurs to me that I took your post a bit too literally.&lt;BR /&gt;&lt;BR /&gt;Should you want only the first matching line of *any* block, as for example to substitute about "Mar 2":&lt;BR /&gt;&lt;BR /&gt;Mar 1&lt;BR /&gt;Mar 1&lt;BR /&gt;&lt;H1&gt;Mar 2&lt;/H1&gt;&lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 3&lt;BR /&gt; &lt;BR /&gt;...then:&lt;BR /&gt;&lt;BR /&gt;# sed -e 's/Mar 2/\&lt;H1&gt;&amp;amp;\&amp;lt;\/h1\&amp;gt;/;n' file&lt;BR /&gt;&lt;BR /&gt;This works for the original case too, but is appropriately general to the span of the entire file.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/H1&gt;</description>
      <pubDate>Fri, 10 Mar 2006 13:07:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748847#M101625</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-10T13:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748848#M101626</link>
      <description>I wasn't clear enough.&lt;BR /&gt;&lt;BR /&gt;Basically I'm putting in Headers for each Day of a month from a log.&lt;BR /&gt;&lt;BR /&gt;So using my previous example the output would be:&lt;BR /&gt;&lt;BR /&gt;&lt;H1&gt;Mar 1&lt;/H1&gt;&lt;BR /&gt;Mar 1&lt;BR /&gt;&lt;H1&gt;Mar 2&lt;/H1&gt;&lt;BR /&gt;Mar 2&lt;BR /&gt;etc...for the rest of the days.&lt;BR /&gt;&lt;BR /&gt;So really my pattern to match is &lt;BR /&gt;"Mar [ 0-9][0-9]" which would match Mar 1 to Mar 31.&lt;BR /&gt;&lt;BR /&gt;Preceding the search with 1 (1s/Mar 1/)just matches the first line input and not the first occurence so that's not doing what I need.&lt;BR /&gt;&lt;BR /&gt;Any more thoughts?&lt;BR /&gt;</description>
      <pubDate>Fri, 10 Mar 2006 13:09:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748848#M101626</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2006-03-10T13:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748849#M101627</link>
      <description>Thanks James.  I was surprised to find your answer posted prior to  my attempted clarification.</description>
      <pubDate>Fri, 10 Mar 2006 13:11:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748849#M101627</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2006-03-10T13:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748850#M101628</link>
      <description>Hi (again) Kevin:&lt;BR /&gt;&lt;BR /&gt;Well, the 'sed' solution I posted worked for the particular repetition of lines you posted, but it *fails* for more generalized matching.  I should have gone straight for Perl.&lt;BR /&gt;&lt;BR /&gt;Consider a file that looks like:&lt;BR /&gt;&lt;BR /&gt;Mar 1&lt;BR /&gt;Mar 1&lt;BR /&gt;Mar 1&lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 3&lt;BR /&gt;Mar 4&lt;BR /&gt;the end at Mar 4 the end!&lt;BR /&gt;&lt;BR /&gt;With the 'sed' solution:&lt;BR /&gt;&lt;BR /&gt;#  sed -e 's/Mar [0-9[0-9]/\&lt;H1&gt;&amp;amp;\&amp;lt;\/h1\&amp;gt;/;n' file&lt;BR /&gt;&lt;BR /&gt;...you get:&lt;BR /&gt;&lt;BR /&gt;&lt;/H1&gt;&lt;H1&gt;Mar 1&lt;/H1&gt;&lt;BR /&gt;Mar 1&lt;BR /&gt;&lt;H1&gt;Mar 1&lt;/H1&gt;&lt;BR /&gt;Mar 2&lt;BR /&gt;&lt;H1&gt;Mar 2&lt;/H1&gt;&lt;BR /&gt;Mar 2&lt;BR /&gt;&lt;H1&gt;Mar 2&lt;/H1&gt;&lt;BR /&gt;Mar 3&lt;BR /&gt;&lt;H1&gt;Mar 4&lt;/H1&gt;&lt;BR /&gt;the end at Mar 4 the end!&lt;BR /&gt;&lt;BR /&gt;...which is not much use.&lt;BR /&gt;&lt;BR /&gt;*Instead* use:&lt;BR /&gt;&lt;BR /&gt;# perl -ple chomp;unless ($prev=~$_) {s%(.*)(Mar \d+)(.*)%$1&lt;H1&gt;$2&lt;/H1&gt;$3%};$prev=$_' file&lt;BR /&gt;&lt;BR /&gt;...and you can have:&lt;BR /&gt;&lt;BR /&gt;&lt;H1&gt;Mar 1&lt;/H1&gt;&lt;BR /&gt;Mar 1&lt;BR /&gt;Mar 1&lt;BR /&gt;&lt;H1&gt;Mar 2&lt;/H1&gt;&lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 2&lt;BR /&gt;Mar 2&lt;BR /&gt;&lt;H1&gt;Mar 3&lt;/H1&gt;&lt;BR /&gt;&lt;H1&gt;Mar 4&lt;/H1&gt;&lt;BR /&gt;the end at &lt;H1&gt;Mar 4&lt;/H1&gt; the end!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 10 Mar 2006 15:35:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748850#M101628</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-10T15:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748851#M101629</link>
      <description>Hi JRF&lt;BR /&gt;&lt;BR /&gt;I get a `(' unexpected error when running that line of perl.&lt;BR /&gt;&lt;BR /&gt;Is there a ( missing?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Mar 2006 11:39:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748851#M101629</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2006-03-13T11:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748852#M101630</link>
      <description>JRF &lt;BR /&gt;&lt;BR /&gt;I have text after the "Mar  1" or "Mar 22" etc.&lt;BR /&gt;&lt;BR /&gt;When I run the perl against it the &lt;H1&gt; and &lt;/H1&gt; is put around the Date but for EVERY line.  I just want the header for the first occurence of each Date.  &lt;BR /&gt;&lt;BR /&gt;I'm stumped.  You prev sed example worked on my test data but not when I plug it into my script. &lt;BR /&gt;&lt;BR /&gt;I'll just keep pluggin away until this works.&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;&lt;BR /&gt;&lt;H1&gt;Mar 13&lt;/H1&gt; 06:53:28 hpkju gconfd (root-28106): starting (version 1.0.9), pid 28106 user 'root'&lt;BR /&gt;&lt;BR /&gt;&lt;H1&gt;Mar 13&lt;/H1&gt; 06:53:27 hpkju gnome-name-server[28098]: starting&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Mar 2006 11:49:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748852#M101630</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2006-03-13T11:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748853#M101631</link>
      <description>Hi Kevin:&lt;BR /&gt;&lt;BR /&gt;It looks like the paste failed.  Try this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    chomp;&lt;BR /&gt;    unless ($prev =~ $_) {&lt;BR /&gt;        s%(Mar \d+)%&lt;H1&gt;$1&lt;/H1&gt;%;&lt;BR /&gt;    }&lt;BR /&gt;    $prev = $_;&lt;BR /&gt;    print  "$_\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 13 Mar 2006 11:52:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748853#M101631</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-13T11:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748854#M101632</link>
      <description>Hi (again) Kevin:&lt;BR /&gt;&lt;BR /&gt;# perl -ple 'chomp;unless ($prev=~$_) {s%(.*)(Mar\s+\d+)(.*)%$1&lt;H1&gt;$2&lt;/H1&gt;$3%};$prev=$_' file&lt;BR /&gt;&lt;BR /&gt;...the first single quote was simply dropped.   &lt;BR /&gt;&lt;BR /&gt;I have added, both for clarity, and better matching, a whitespace (\s) one or more times after the "Mar" is the regular expression.  You could change the prior post too.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 13 Mar 2006 11:58:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748854#M101632</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-13T11:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748855#M101633</link>
      <description>This 'one liner' works for me under a Windows CMD shell.&lt;BR /&gt;It does nto look just for "Mar" but defines a date as a line starting with an Upppercase, two lowercase, some whitespace and some decimals:&lt;BR /&gt;&lt;BR /&gt;#  type tmp.txt&lt;BR /&gt;Mar 1 aap&lt;BR /&gt;Mar 1 noot&lt;BR /&gt;Mar 1  mies&lt;BR /&gt;Mar 2  teun&lt;BR /&gt;Mar 2 vuur&lt;BR /&gt;Apr 2&lt;BR /&gt;Apr 2&lt;BR /&gt;Apr 3&lt;BR /&gt;Apr 4&lt;BR /&gt;&lt;BR /&gt;#  perl -pe "if (/^([A-Z][a-z][a-z]\s+\d+)/ &amp;amp;&amp;amp;  $1 ne $last) { $last=$1; $x='&lt;H1&gt;'.$1.'&amp;lt;\h1&amp;gt;'; s/$1/$x/}" tmp.txt&lt;BR /&gt;&lt;BR /&gt;&lt;/H1&gt;&lt;H1&gt;Mar 1&amp;lt;\h1&amp;gt; aap&lt;BR /&gt;Mar 1 noot&lt;BR /&gt;Mar 1  mies&lt;BR /&gt;&lt;/H1&gt;&lt;H1&gt;Mar 2&amp;lt;\h1&amp;gt;  teun&lt;BR /&gt;Mar 2 vuur&lt;BR /&gt;&lt;/H1&gt;&lt;H1&gt;Apr 2&amp;lt;\h1&amp;gt;&lt;BR /&gt;Apr 2&lt;BR /&gt;&lt;/H1&gt;&lt;H1&gt;Apr 3&amp;lt;\h1&amp;gt;&lt;BR /&gt;&lt;/H1&gt;&lt;H1&gt;Apr 4&amp;lt;\h1&amp;gt;&lt;BR /&gt;&lt;BR /&gt;You'll have to play with the quotes to make it work for hpux&lt;BR /&gt;&lt;BR /&gt;Or stick it in a script:&lt;BR /&gt;&lt;BR /&gt;--------- tmp.pl --------------&lt;BR /&gt;if (/^([A-Z][a-z][a-z]\s+\d+)/ &amp;amp;&amp;amp;  $1 ne $last) &lt;BR /&gt;   { &lt;BR /&gt;   $last=$1; &lt;BR /&gt;   $x='&lt;/H1&gt;&lt;H1&gt;'.$1.'&amp;lt;\h1&amp;gt;';&lt;BR /&gt;   s/$1/$x/;&lt;BR /&gt;   }&lt;BR /&gt;&lt;BR /&gt;----------------&lt;BR /&gt;perl -p tmp.pl tmp.txt&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy...&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;/H1&gt;</description>
      <pubDate>Mon, 13 Mar 2006 12:17:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748855#M101633</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-03-13T12:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748856#M101634</link>
      <description>Hi Kevin:&lt;BR /&gt;&lt;BR /&gt;Maybe I finally understand your requirement.  Try this with your data.&lt;BR /&gt;&lt;BR /&gt;# cat perl.pl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my  $month = "Mar";&lt;BR /&gt;my ($curr, $prev) = (".", ".");&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    chomp;&lt;BR /&gt;    $curr = $2 if $_ =~ m%(.*)(\b$month\s+\d+\b)(.*)%;&lt;BR /&gt;    unless ($curr eq $prev) {&lt;BR /&gt;        s%(.*)(\b$month\s+\d+\b)(.*)%&lt;H1&gt;$1$2$3&lt;/H1&gt;%;&lt;BR /&gt;        $prev = $2;&lt;BR /&gt;    }&lt;BR /&gt;    print "$_\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;# ./perl.pl file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 13 Mar 2006 13:14:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748856#M101634</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-13T13:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748857#M101635</link>
      <description>Hi Kevin:&lt;BR /&gt;&lt;BR /&gt;Here's a more robust variation for your use.  &lt;BR /&gt;&lt;BR /&gt;# cat perl.pl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my  $mon   = shift;&lt;BR /&gt;my  $file  = shift or die "Usage: $0 monthname file\n";&lt;BR /&gt;open(FH, "&amp;lt;", "$file") or die "Can't open $file: $!\n";&lt;BR /&gt;my  $patt  = qr"(.*)(\b(?i)$mon\s+\d+\b)(.*)";&lt;BR /&gt;my ($curr, $prev) = (".", ".");&lt;BR /&gt;while (&lt;FH&gt;) {&lt;BR /&gt;    chomp;&lt;BR /&gt;    $curr = $2 if m%$patt%;&lt;BR /&gt;    s%$patt%&lt;H1&gt;$1$2$3&lt;/H1&gt;% unless ($curr eq $prev);&lt;BR /&gt;    $prev = $2 if defined($2);&lt;BR /&gt;    print "$_\n";&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;Run as:&lt;BR /&gt;&lt;BR /&gt;# ./perl.pl monthname file&lt;BR /&gt;&lt;BR /&gt;...for example:&lt;BR /&gt;&lt;BR /&gt;# ./perl.pl mar mylog&lt;BR /&gt;&lt;BR /&gt;Note that the abbreviated month name will be matched case-insenitively.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/FH&gt;</description>
      <pubDate>Mon, 13 Mar 2006 16:16:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748857#M101635</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-13T16:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Matching first line iwth a specific string</title>
      <link>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748858#M101636</link>
      <description>Hi Kevin,&lt;BR /&gt;&lt;BR /&gt;I don't know if it'll help at this stage since you may be pursuing a different solution altogether but this awk construct does what you are looking for i.e. encapsulate the header date in the input file.&lt;BR /&gt;&lt;BR /&gt;=================myawk.cmd===================&lt;BR /&gt;{&lt;BR /&gt;    if (prev!=$1$2) {&lt;BR /&gt;        printf("%s %s",b$1,($2&amp;lt;10?" "$2e:$2e))&lt;BR /&gt;        for (i=3;i&amp;lt;=NF;++i)&lt;BR /&gt;            printf(" %s",$i)&lt;BR /&gt;        printf("\n")&lt;BR /&gt;        prev=$1$2&lt;BR /&gt;    } else&lt;BR /&gt;        print $0&lt;BR /&gt;}&lt;BR /&gt;=============================================&lt;BR /&gt;&lt;BR /&gt;Create a file named "myawk.cmd" with the commands above and execute as:&lt;BR /&gt;&lt;BR /&gt;# awk -f myawk.cmd b="&lt;H1&gt;" e="&lt;/H1&gt;" infile&lt;BR /&gt;&lt;BR /&gt;where "b" and "e" are variables containing the characters you want to surround the header date with.&lt;BR /&gt;&lt;BR /&gt;cheers!</description>
      <pubDate>Mon, 13 Mar 2006 20:12:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/matching-first-line-iwth-a-specific-string/m-p/3748858#M101636</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-03-13T20:12:05Z</dc:date>
    </item>
  </channel>
</rss>

