<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Thu May 23, 2013 10:56 pm by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Thu May 23, 2013 10:56 pm</pubDate>
  <lastBuildDate>Thu May 23, 2013 10:56 pm</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>Re: Bash script - Truncating Variable</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=107968#107968</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=2793'&gt;MartyBartfast&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Sat Sep 22, 2012 7:48 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      good find, could come in very handy, I've used awk for such things but always thought it was a bit cluncky.</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=107968#107968</comments>
                                        <author>MartyBartfast</author>
                                        <pubDate>Sat Sep 22, 2012 7:48 am</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=107968#107968</guid>
                                      </item>
                                      <item>
                                        <title>Re: Bash script - Truncating Variable</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=107967#107967</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5304'&gt;Arthur_Dent&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Sat Sep 22, 2012 7:16 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Replying to my own post:&lt;br /&gt;
&lt;br /&gt;
I have found a solution to this. I'm sure there are better ways, but this works.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;# Define the newline character to be found and stripped out&amp;#58;&lt;br /&gt;
NL=&amp;quot;&lt;br /&gt;
&amp;quot;&lt;br /&gt;
# I tried variations of &amp;quot;\n&amp;quot; but that didn't seem to work.&lt;br /&gt;
CLAMERROR=$&amp;#123;CLAMVERS%$NL*&amp;#125;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
The %{string}* thing means strip out everything after and including {string}. There is an equivalent directive #*{string} which means strip out everything up to and including {string}. I had never come across the % and # directives in string handling before. It does what I want anyway...</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=107967#107967</comments>
                                        <author>Arthur_Dent</author>
                                        <pubDate>Sat Sep 22, 2012 7:16 am</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=107967#107967</guid>
                                      </item>
                                      <item>
                                        <title>Bash script - Truncating Variable</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=107947#107947</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5304'&gt;Arthur_Dent&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Sep 20, 2012 7:46 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Hello all,&lt;br /&gt;
&lt;br /&gt;
I don't speak fluent bash. I can just about order a beer in a bar, but I am a long way off being able to chat with a local.&lt;br /&gt;
&lt;br /&gt;
I use a script called clamassassin to pipe emails through clamd. It marks up the email headers (using formail) with the results of the scan. The problem is that the script has not been developed since 2007 and the author cannot be contacted. There is a fault with the script and I am trying to fix it myself but my bash scripting skills are letting me down.&lt;br /&gt;
&lt;br /&gt;
The script first obtains the clamd version but calling &amp;quot;clamdscan -V&amp;quot; and reading it into a variable called $CLAMVERS. If there is a problem with clamd (daemon not running - file permission... whatever...) it returns something like:&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;ERROR&amp;#58; Can't connect to clamd&amp;#58; Permission denied&lt;br /&gt;
ClamAV 0.97.5&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
Note that there is a line-break in there. When the script goes on to put this into the headers using formail the line-break corrupts the email.&lt;br /&gt;
&lt;br /&gt;
I am trying to fix this, but still retain the error detail, by cutting off the line break and the ClamAV... part.&lt;br /&gt;
&lt;br /&gt;
This is where I need help...&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;# Set version header string&lt;br /&gt;
CLAMVERS=`$&amp;#123;CLAMSCAN&amp;#125; -V --stdout`&lt;br /&gt;
&lt;br /&gt;
if &amp;#91;&amp;#91; &amp;quot;$CLAMVERS&amp;quot; == *ERROR* &amp;#93;&amp;#93; # Not how it works in the script, but OK for testing&lt;br /&gt;
then &lt;br /&gt;
&amp;nbsp; &amp;nbsp;ERRORMSG=`echo $&amp;#123;CLAMVERS&amp;#125; | sed -e &amp;quot;/ClamAV/!d&amp;quot; -e &amp;quot;s/.* //&amp;quot;`&lt;br /&gt;
&amp;nbsp; &amp;nbsp;echo &amp;quot;Error = &amp;#58;$&amp;#123;ERRORMSG&amp;#125;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
else&lt;br /&gt;
&amp;nbsp; &amp;nbsp;echo &amp;quot;ClamVersion = $CLAMVERS&amp;quot;&lt;br /&gt;
fi&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
Essentially I want to cut off anything after the ClamAV part and the character before that (the line break).&lt;br /&gt;
&lt;br /&gt;
I'm stuck.&lt;br /&gt;
&lt;br /&gt;
Any fluent bash speakers care to help me?&lt;br /&gt;
&lt;br /&gt;
Thanks in advance.&lt;br /&gt;
&lt;br /&gt;
Mark</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=107947#107947</comments>
                                        <author>Arthur_Dent</author>
                                        <pubDate>Thu Sep 20, 2012 7:46 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=107947#107947</guid>
                                      </item></channel></rss>