<?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: While Read a File in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081865#M92597</link>
    <description>i cant beleive you guys missed the details.&lt;BR /&gt;&lt;BR /&gt;Pete, you know the # should be at the begining of the line and therefore your grep should be anchored to the begining of the line:  grep -v "^\#"&lt;BR /&gt;&lt;BR /&gt;and James, your solutions assumes there is always a space after the #, as in:&lt;BR /&gt;# thisworks&lt;BR /&gt;#thisdoesn't&lt;BR /&gt;&lt;BR /&gt;and you improve performance by eliminating the cat, but still run mailx for each address&lt;BR /&gt;&lt;BR /&gt;something like this would be better,&lt;BR /&gt;comments can be at the end of the line, &lt;BR /&gt;as in: &lt;BR /&gt;addr # to me  &lt;BR /&gt;&lt;BR /&gt;will work and it creates a variable of the addresses and runs mailx just once&lt;BR /&gt;&lt;BR /&gt;addrs=""&lt;BR /&gt;while read myAddr&lt;BR /&gt;do&lt;BR /&gt;myAddr=${myAddr%%#.*}  #remove first # and everything on the line after it&lt;BR /&gt;myAddr=${myAddr%%#}    #remove # if it is last character on the line or only character&lt;BR /&gt;addrs="${addrs} ${myAddr}"&lt;BR /&gt;done &amp;lt; email_list&lt;BR /&gt;&lt;BR /&gt;mailx -s sub $addrs</description>
    <pubDate>Wed, 28 Nov 2007 17:36:51 GMT</pubDate>
    <dc:creator>blah2blah</dc:creator>
    <dc:date>2007-11-28T17:36:51Z</dc:date>
    <item>
      <title>While Read a File</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081861#M92593</link>
      <description>I have a simple one.  I have a script with the following lines:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;cat email_list | while read L&lt;BR /&gt; do&lt;BR /&gt;  mailx -s "Test Data" $L &amp;lt; /dev/null&lt;BR /&gt; done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The email_list is a file with various email address, one line per email address.  Let's say I have 10 entries and I want to comment out one line with an "#".  Now when my script runs, I want to send an email out to 9 people instead of 10.  I want to comment out the address rather than delete it.  How can I set up my "while read" instruction to bypass any lines with an "#" in it?</description>
      <pubDate>Wed, 28 Nov 2007 14:27:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081861#M92593</guid>
      <dc:creator>Bob Ferro</dc:creator>
      <dc:date>2007-11-28T14:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: While Read a File</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081862#M92594</link>
      <description>Bob,&lt;BR /&gt;&lt;BR /&gt;For my simple mind, the following works:&lt;BR /&gt;&lt;BR /&gt;for L in `cat email_list |grep -v '#'`&lt;BR /&gt;do&lt;BR /&gt;mailx -s "Test Data" $L &amp;lt; /dev/null&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Wed, 28 Nov 2007 14:46:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081862#M92594</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2007-11-28T14:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: While Read a File</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081863#M92595</link>
      <description>Bam!&lt;BR /&gt;&lt;BR /&gt;Pete, it worked like a charm.  Thanks again.</description>
      <pubDate>Wed, 28 Nov 2007 15:00:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081863#M92595</guid>
      <dc:creator>Bob Ferro</dc:creator>
      <dc:date>2007-11-28T15:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: While Read a File</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081864#M92596</link>
      <description>Hi Bob:&lt;BR /&gt;&lt;BR /&gt;One simple way:&lt;BR /&gt;&lt;BR /&gt;# cat ./mailer&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while read X L&lt;BR /&gt;do&lt;BR /&gt;    [ ${X} = "#" ] &amp;amp;&amp;amp; continue&lt;BR /&gt;    mailx -s "Test Data" ${L} &amp;lt; /dev/null&lt;BR /&gt;&lt;BR /&gt;done &amp;lt; email_list&lt;BR /&gt;&lt;BR /&gt;If your file has a "#" field as the first field of the line it will be skipped.&lt;BR /&gt;&lt;BR /&gt;Notice, too that your can eliminate the 'cat' process.  The loop reads your file directly.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Nov 2007 15:01:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081864#M92596</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-11-28T15:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: While Read a File</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081865#M92597</link>
      <description>i cant beleive you guys missed the details.&lt;BR /&gt;&lt;BR /&gt;Pete, you know the # should be at the begining of the line and therefore your grep should be anchored to the begining of the line:  grep -v "^\#"&lt;BR /&gt;&lt;BR /&gt;and James, your solutions assumes there is always a space after the #, as in:&lt;BR /&gt;# thisworks&lt;BR /&gt;#thisdoesn't&lt;BR /&gt;&lt;BR /&gt;and you improve performance by eliminating the cat, but still run mailx for each address&lt;BR /&gt;&lt;BR /&gt;something like this would be better,&lt;BR /&gt;comments can be at the end of the line, &lt;BR /&gt;as in: &lt;BR /&gt;addr # to me  &lt;BR /&gt;&lt;BR /&gt;will work and it creates a variable of the addresses and runs mailx just once&lt;BR /&gt;&lt;BR /&gt;addrs=""&lt;BR /&gt;while read myAddr&lt;BR /&gt;do&lt;BR /&gt;myAddr=${myAddr%%#.*}  #remove first # and everything on the line after it&lt;BR /&gt;myAddr=${myAddr%%#}    #remove # if it is last character on the line or only character&lt;BR /&gt;addrs="${addrs} ${myAddr}"&lt;BR /&gt;done &amp;lt; email_list&lt;BR /&gt;&lt;BR /&gt;mailx -s sub $addrs</description>
      <pubDate>Wed, 28 Nov 2007 17:36:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-read-a-file/m-p/5081865#M92597</guid>
      <dc:creator>blah2blah</dc:creator>
      <dc:date>2007-11-28T17:36:51Z</dc:date>
    </item>
  </channel>
</rss>

