<?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: printf formatting help in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111155#M91564</link>
    <description>&amp;gt;I think I got it:&lt;BR /&gt;awk -F":" '&lt;BR /&gt;/^SAL/ {&lt;BR /&gt;SAL = $3&lt;BR /&gt;/^SKM/&lt;BR /&gt;SKM = $3&lt;BR /&gt;print $2,SKM,SAL}' FILE&lt;BR /&gt;&lt;BR /&gt;I don't see how.&lt;BR /&gt;The first RE makes sure it starts with SAL.  The second RE is nested within the first condition so it can't be true at the same time.&lt;BR /&gt;&lt;BR /&gt;If you are always ordered SAL then SKM, perhaps you meant:&lt;BR /&gt;/^SAL/ {SAL = $3; next}&lt;BR /&gt;/^SKM/ {&lt;BR /&gt;SKM = $3&lt;BR /&gt;print $2,SKM,SAL}' FILE</description>
    <pubDate>Thu, 29 May 2008 12:00:36 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2008-05-29T12:00:36Z</dc:date>
    <item>
      <title>printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111146#M91555</link>
      <description>Hello all,&lt;BR /&gt;&lt;BR /&gt;I need some help with printf ....&lt;BR /&gt;&lt;BR /&gt;I have a file that looks like:&lt;BR /&gt;&lt;BR /&gt;SAL:FPGW:Running&lt;BR /&gt;SAL:runmqlsr:Running&lt;BR /&gt;SKM:FPGW:Running&lt;BR /&gt;SKM:runmqlsr:Running&lt;BR /&gt;&lt;BR /&gt;I want to print the fields accross the screen to a certain format:&lt;BR /&gt;&lt;BR /&gt;FPGW       Running     Running&lt;BR /&gt;runmqlsr   Running     Running&lt;BR /&gt;&lt;BR /&gt;so I write an awk statement:&lt;BR /&gt;&lt;BR /&gt;awk -F":" '/^SAL/ {(SAL = $3);/^SKM/ (SKM = $3); printf "%-15s\t%10s\n", $2,SAL"\t"SKM}' &lt;FILE&gt; &lt;BR /&gt;&lt;BR /&gt;and the output looks like:&lt;BR /&gt;&lt;BR /&gt;FPGW            Running     Running&lt;BR /&gt;runmqlsr        Running     Running&lt;BR /&gt;&lt;BR /&gt;however I want it to look like this and cant work it out - please help :-)&lt;BR /&gt;&lt;BR /&gt;FPGW         Running                     Running&lt;BR /&gt;runmqlsr     Running                     Running&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;&lt;BR /&gt;Chris.&lt;/FILE&gt;</description>
      <pubDate>Thu, 29 May 2008 06:46:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111146#M91555</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-29T06:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111147#M91556</link>
      <description>hmmmm its not printed to the web as I expected so I will use "\t" to denote the tabs:&lt;BR /&gt;&lt;BR /&gt;FPGW"\t\t"Running"\t\t\t\t\t\t"Running&lt;BR /&gt;runmqlsr"\t\t"Running"\t\t\t\t\t\t"Running&lt;BR /&gt;&lt;BR /&gt;thanks</description>
      <pubDate>Thu, 29 May 2008 06:52:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111147#M91556</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-29T06:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111148#M91557</link>
      <description>I have a solution but pretty sure this can be done better with proper printf formatting:&lt;BR /&gt;&lt;BR /&gt;awk -F":" '/^SAL/ {(SAL = $3);/^SKM/ (SKM = $3); printf " %-15s\t%0s\n", $2,SAL"\t\t\t\t\t\t"SKM}' FILE.</description>
      <pubDate>Thu, 29 May 2008 07:23:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111148#M91557</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-29T07:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111149#M91558</link>
      <description>I'm not sure what you are trying to do.  Nor even why awk doesn't complaint about your syntax.  You seem to have:&lt;BR /&gt;awk -F":" '&lt;BR /&gt;/^SAL/ {&lt;BR /&gt;(SAL = $3)  # why () here?&lt;BR /&gt;/^SKM/ (SKM = $3)  # HUH??&lt;BR /&gt;printf "%-15s\t%10s\n", $2,SAL"\t"SKM&lt;BR /&gt;} ' &lt;FILE&gt;&lt;BR /&gt;&lt;BR /&gt;I have no idea what "^SKM/ (SKM = $3)" does.  It seems to always do the assignment.&lt;BR /&gt;&lt;BR /&gt;If you want two tabs between the first %s and the next, you need to replace that %-15s\t%10s by just %s\t\t%s.&lt;BR /&gt;&lt;BR /&gt;Also, why bother with SAL"\t"SKM, when you can do that in the printf format?  (printf may be slower than concatenation though.)&lt;/FILE&gt;</description>
      <pubDate>Thu, 29 May 2008 09:34:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111149#M91558</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-29T09:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111150#M91559</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;Another way -- a hash (associative array) to hold the data and print it afterwards:&lt;BR /&gt;&lt;BR /&gt;# perl -ne 'chomp;@a=split /:/;push(@{$line{$a[1]}},$a[2]);END{for $x (sort keys %line) {printf "%-10s %s\n",$x,"@{$line{$x}"}}}' file&lt;BR /&gt;&lt;BR /&gt;...yields:&lt;BR /&gt;&lt;BR /&gt;FPGW       Running Running&lt;BR /&gt;runmqlsr   Running Running&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 29 May 2008 11:01:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111150#M91559</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-29T11:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111151#M91560</link>
      <description>Thanks both,&lt;BR /&gt;&lt;BR /&gt;Dennis I am still getting to grips with awk so I am not sure of any other way.&lt;BR /&gt;&lt;BR /&gt;I try putting parenthesis around section of the awk but do not get the required output.&lt;BR /&gt;&lt;BR /&gt;what do you suggest?</description>
      <pubDate>Thu, 29 May 2008 11:45:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111151#M91560</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-29T11:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111152#M91561</link>
      <description>You haven't specified what you want, just the column format.  Start with this:&lt;BR /&gt;SAL:FPGWL:Running1&lt;BR /&gt;SAL:runmqlsrL:Running2&lt;BR /&gt;SKM:FPGWM:Running3&lt;BR /&gt;SKM:runmqlsrM:Running4&lt;BR /&gt;&lt;BR /&gt;What do you want for the output?</description>
      <pubDate>Thu, 29 May 2008 11:49:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111152#M91561</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-29T11:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111153#M91562</link>
      <description>I think I got it:&lt;BR /&gt;&lt;BR /&gt;awk -F":" '&lt;BR /&gt;/^SAL/ {&lt;BR /&gt;SAL = $3&lt;BR /&gt;/^SKM/&lt;BR /&gt;SKM = $3&lt;BR /&gt;print $2,SKM,SAL}' FILE&lt;BR /&gt;&lt;BR /&gt;(without the printf off course .....&lt;BR /&gt;</description>
      <pubDate>Thu, 29 May 2008 11:49:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111153#M91562</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-29T11:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111154#M91563</link>
      <description>FPGW Running Running&lt;BR /&gt;runmqlsr Running Running&lt;BR /&gt;&lt;BR /&gt;with tabs formatting to the screen - which I now have from the printf.&lt;BR /&gt;&lt;BR /&gt;This is being added to a script where SAL and SKM are 2  sites and the next field are the services running or not ....&lt;BR /&gt;&lt;BR /&gt;thanks all the same &lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Thu, 29 May 2008 11:52:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111154#M91563</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-29T11:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111155#M91564</link>
      <description>&amp;gt;I think I got it:&lt;BR /&gt;awk -F":" '&lt;BR /&gt;/^SAL/ {&lt;BR /&gt;SAL = $3&lt;BR /&gt;/^SKM/&lt;BR /&gt;SKM = $3&lt;BR /&gt;print $2,SKM,SAL}' FILE&lt;BR /&gt;&lt;BR /&gt;I don't see how.&lt;BR /&gt;The first RE makes sure it starts with SAL.  The second RE is nested within the first condition so it can't be true at the same time.&lt;BR /&gt;&lt;BR /&gt;If you are always ordered SAL then SKM, perhaps you meant:&lt;BR /&gt;/^SAL/ {SAL = $3; next}&lt;BR /&gt;/^SKM/ {&lt;BR /&gt;SKM = $3&lt;BR /&gt;print $2,SKM,SAL}' FILE</description>
      <pubDate>Thu, 29 May 2008 12:00:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111155#M91564</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-29T12:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111156#M91565</link>
      <description>ok thanks Dennis,&lt;BR /&gt;&lt;BR /&gt;I can see that now ....&lt;BR /&gt;&lt;BR /&gt;I havent come across the "next" statement until now so much appreciated.&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Thu, 29 May 2008 12:15:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111156#M91565</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-29T12:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: printf formatting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111157#M91566</link>
      <description>&amp;gt;I haven't come across the "next" statement&lt;BR /&gt;&lt;BR /&gt;next wasn't really needed but it does simply the logic some.  Just like return is better than deeply nested if blocks or flag programming.  And of course better than gotos. :-)</description>
      <pubDate>Thu, 29 May 2008 12:19:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/printf-formatting-help/m-p/5111157#M91566</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-29T12:19:24Z</dc:date>
    </item>
  </channel>
</rss>

