<?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 combine records in file with awk? in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921940#M104533</link>
    <description>I have a file that looks like this:&lt;BR /&gt;&lt;BR /&gt; 270095000   1527    REG      8838720  vgeb_rdp0_q   c100t5d2 &lt;BR /&gt;   270095000   1527    REG      8838720  vgeb_rdp0_q    c91t5d2 &lt;BR /&gt;   270098000   1527   M(8)     70709760        Avail   c100t5d5 &lt;BR /&gt;   270098000   1527   M(8)     70709760        Avail    c91t5d5 &lt;BR /&gt;   2700A5000   1527   M(8)     70709760        Avail   c100t2d2 &lt;BR /&gt;   2700A5000   1527   M(8)     70709760        Avail    c91t2d2 &lt;BR /&gt;   2700A7000   1527   M(8)     70709760        Avail   c100t1d6 &lt;BR /&gt;   2700A7000   1527   M(8)     70709760        Avail    c91t1d6 &lt;BR /&gt;   2700C5000   1527    REG      8838720  vgeb_rdp0_q  c101t10d7 &lt;BR /&gt;   2700C5000   1527    REG      8838720  vgeb_rdp0_q   c92t10d7 &lt;BR /&gt;&lt;BR /&gt;We combine a daily "syminq" with "/etc/lvmtab" to figure out which PVs/HVs are in what volume groups.&lt;BR /&gt;&lt;BR /&gt;I want to combine records where field 1 is the same, in such a way that I get the complete record 1, and the LAST FIELD from subsequent records with the same field 1:&lt;BR /&gt;&lt;BR /&gt; 270095000   1527    REG      8838720  vgeb_rdp0_q   c100t5d2 c91t5d2 &lt;BR /&gt;&lt;BR /&gt;Can you do that with awk?  (We already do it with "ksh" but it's clumsy.)&lt;BR /&gt;</description>
    <pubDate>Tue, 30 Aug 2005 07:47:21 GMT</pubDate>
    <dc:creator>Stuart Abramson</dc:creator>
    <dc:date>2005-08-30T07:47:21Z</dc:date>
    <item>
      <title>combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921940#M104533</link>
      <description>I have a file that looks like this:&lt;BR /&gt;&lt;BR /&gt; 270095000   1527    REG      8838720  vgeb_rdp0_q   c100t5d2 &lt;BR /&gt;   270095000   1527    REG      8838720  vgeb_rdp0_q    c91t5d2 &lt;BR /&gt;   270098000   1527   M(8)     70709760        Avail   c100t5d5 &lt;BR /&gt;   270098000   1527   M(8)     70709760        Avail    c91t5d5 &lt;BR /&gt;   2700A5000   1527   M(8)     70709760        Avail   c100t2d2 &lt;BR /&gt;   2700A5000   1527   M(8)     70709760        Avail    c91t2d2 &lt;BR /&gt;   2700A7000   1527   M(8)     70709760        Avail   c100t1d6 &lt;BR /&gt;   2700A7000   1527   M(8)     70709760        Avail    c91t1d6 &lt;BR /&gt;   2700C5000   1527    REG      8838720  vgeb_rdp0_q  c101t10d7 &lt;BR /&gt;   2700C5000   1527    REG      8838720  vgeb_rdp0_q   c92t10d7 &lt;BR /&gt;&lt;BR /&gt;We combine a daily "syminq" with "/etc/lvmtab" to figure out which PVs/HVs are in what volume groups.&lt;BR /&gt;&lt;BR /&gt;I want to combine records where field 1 is the same, in such a way that I get the complete record 1, and the LAST FIELD from subsequent records with the same field 1:&lt;BR /&gt;&lt;BR /&gt; 270095000   1527    REG      8838720  vgeb_rdp0_q   c100t5d2 c91t5d2 &lt;BR /&gt;&lt;BR /&gt;Can you do that with awk?  (We already do it with "ksh" but it's clumsy.)&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Aug 2005 07:47:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921940#M104533</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2005-08-30T07:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921941#M104534</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;sort &lt;YOURFILENAME&gt; | awk '&lt;BR /&gt;BEGIN{fld1=$1;printf("%s",$0); getline;}&lt;BR /&gt;{if($1==fld1) { printf("%s",$6); } &lt;BR /&gt;  else { fld1=$1; printf("\n%s",$0); }&lt;BR /&gt;}&lt;BR /&gt;END{printf("\n")}'&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Jean-Luc&lt;/YOURFILENAME&gt;</description>
      <pubDate>Tue, 30 Aug 2005 08:30:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921941#M104534</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2005-08-30T08:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921942#M104535</link>
      <description>Check this script out.&lt;BR /&gt;Gathers all disk information, reports vg, lv, mounts, size, and free extents&lt;BR /&gt;&lt;BR /&gt;Output in both formatted text and csv&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Aug 2005 09:15:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921942#M104535</guid>
      <dc:creator>Tim Nelson</dc:creator>
      <dc:date>2005-08-30T09:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921943#M104536</link>
      <description>&lt;BR /&gt;With your data lines in a file 'x', the following seems to work:&lt;BR /&gt;&lt;BR /&gt;awk '{if ($1==old){line = line $NF} else { if (old){print line}; line=$0; old=$1 }}END{print line}' x&lt;BR /&gt;&lt;BR /&gt;270095000 1527 REG 8838720 vgeb_rdp0_q c100t5d2 c91t5d2&lt;BR /&gt;270098000 1527 M(8) 70709760 Avail c100t5d5 c91t5d5&lt;BR /&gt;2700A5000 1527 M(8) 70709760 Avail c100t2d2 c91t2d2&lt;BR /&gt;2700A7000 1527 M(8) 70709760 Avail c100t1d6 c91t1d6&lt;BR /&gt;2700C5000 1527 REG 8838720 vgeb_rdp0_q c101t10d7 c92t10d7&lt;BR /&gt;&lt;BR /&gt;Build up a print line in variable 'line'&lt;BR /&gt;If the current input starts out the same, then add the current last field to 'line'.&lt;BR /&gt;If not the same, print line (unless first), and reset to current input.&lt;BR /&gt;At end print print the final line assembled.&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Aug 2005 11:07:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921943#M104536</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-08-30T11:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921944#M104537</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;did you consider the join command ?&lt;BR /&gt;Should do exactly what you like to do.&lt;BR /&gt;&lt;BR /&gt;Volker&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Aug 2005 11:11:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921944#M104537</guid>
      <dc:creator>Volker Borowski</dc:creator>
      <dc:date>2005-08-30T11:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921945#M104538</link>
      <description>Hi Stuart:&lt;BR /&gt;&lt;BR /&gt;You can easily do this in perl along these lines:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl -an&lt;BR /&gt;if ($F[0] eq $prev) {&lt;BR /&gt;    push( @list, $F[5] )&lt;BR /&gt;} else {&lt;BR /&gt;    print "$prev @list\n" if (@list);&lt;BR /&gt;    $prev = $F[0];&lt;BR /&gt;    @list = ();&lt;BR /&gt;    push( @list, $F[5] );&lt;BR /&gt;}&lt;BR /&gt;END { print "$prev @list\n" }&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 30 Aug 2005 11:48:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921945#M104538</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-08-30T11:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921946#M104539</link>
      <description>I second Hein's awk solution...quite elegantly and artfully done.&lt;BR /&gt;&lt;BR /&gt;regards!</description>
      <pubDate>Tue, 30 Aug 2005 14:16:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921946#M104539</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-08-30T14:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921947#M104540</link>
      <description>All good answers.  Thanks very much.&lt;BR /&gt;&lt;BR /&gt;I forgot something.  Look at this case:&lt;BR /&gt;&lt;BR /&gt;2700A7000 1527 M(8) 70709760 Avail c100t1d6 &lt;BR /&gt;2700A7000 1527 M(8) 70709760 Avail c91t1d6 &lt;BR /&gt;2700C5000 1527 REG 8838720 Avail c101t10d7 &lt;BR /&gt;2700C5000 1527 REG 8838720 vgeb_rd c92t10d7 &lt;BR /&gt;2700C5000 1527 REG 8838720 Avail c95t10d7 &lt;BR /&gt;&lt;BR /&gt;Volume 00C5 is presented 3 times with three device file entries, but only one of them is added to the VG.  So, I want the combined record to look like this:&lt;BR /&gt;&lt;BR /&gt;2700C5000 1527 REG 8838720 vgeb_rd c92t10d7 c101t10d7 c95t10d7&lt;BR /&gt;&lt;BR /&gt;I need some logic that says "if any of the X volumes with the same Serial Number are in a Volume Group, use that VG name, not the Avail name.."&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Aug 2005 07:51:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921947#M104540</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2005-08-31T07:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921948#M104541</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;easy... in my example, just try replace 'Avail' with the current $5 field.&lt;BR /&gt;The will only do something once.&lt;BR /&gt;In an awk  script:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;{if ($1==old) {&lt;BR /&gt; line = line $NF&lt;BR /&gt; sub (/Avail/,$5,line);&lt;BR /&gt; } else {&lt;BR /&gt; if (old) {&lt;BR /&gt;   print line;&lt;BR /&gt;   }&lt;BR /&gt; line=$0;&lt;BR /&gt; old=$1;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;END { print line }&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Aug 2005 08:28:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921948#M104541</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-08-31T08:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921949#M104542</link>
      <description>Stuart,&lt;BR /&gt;&lt;BR /&gt;Here's an awk construct that outputs what you're looking for. It concatenates multiple instances of the first field in the input file with a single stream in the output file.&lt;BR /&gt;&lt;BR /&gt;# awk '&lt;BR /&gt;&amp;gt; {&lt;BR /&gt;&amp;gt;    if(NR==1) {&lt;BR /&gt;&amp;gt;       line=$0&lt;BR /&gt;&amp;gt;       prev=$1&lt;BR /&gt;&amp;gt;    }&lt;BR /&gt;&amp;gt;    else&lt;BR /&gt;&amp;gt;       if($1==prev)&lt;BR /&gt;&amp;gt;          line=line" "$NF&lt;BR /&gt;&amp;gt;       else {&lt;BR /&gt;&amp;gt;          print line&lt;BR /&gt;&amp;gt;          line=$0&lt;BR /&gt;&amp;gt;          prev=$1&lt;BR /&gt;&amp;gt;       }&lt;BR /&gt;&amp;gt; }&lt;BR /&gt;&amp;gt; &lt;BR /&gt;&amp;gt; END {print line}  &lt;BR /&gt;&amp;gt; ' input_file</description>
      <pubDate>Wed, 31 Aug 2005 14:44:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921949#M104542</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-08-31T14:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: combine records in file with awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921950#M104543</link>
      <description>Thanks all, especially Hein.&lt;BR /&gt;&lt;BR /&gt;  Stuart</description>
      <pubDate>Wed, 31 Aug 2005 15:48:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/combine-records-in-file-with-awk/m-p/4921950#M104543</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2005-08-31T15:48:39Z</dc:date>
    </item>
  </channel>
</rss>

