Dave, <br><br>Your right I do. If your going, I'm buying ;) <br><br>Stu<br><br><div class="gmail_quote">On 18 October 2010 22:16, David Holden <span dir="ltr"><<a href="mailto:dh@iucr.org">dh@iucr.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im"><br>
<br>
On 18/10/10 21:49, Stuart Burns wrote:<br>
> Dave, you must be a bash Jedi!<br>
><br>
> It does work, and I can kind of trace how it works, but would you mind<br>
> explaining it a bit more ?<br>
> Cheers muchly. I owe you a beer, if your at the LUG next week ?<br>
<br>
</div>You still owe me a meal matey ;)<br>
<br>
IFS=' ' this set the fields seperator for the "read".<br>
<br>
basically it then loops over the rows, gets the first column (based on<br>
the IFS) echo's it without newline, then for each of these "col1"s cats<br>
the whole file again and picks out col2 (using awk) that have matching<br>
"col1"s, then collapses them to one line using tr '\n' ' ', the final<br>
echo does the newline. This all has to then be sorted and uniq'ed to<br>
remove repetition.<br>
<br>
 Cheers,<br>
<br>
  Dave.<br>
<div class="im"><br>
<br>
<br>
<br>
><br>
> Cheers muchly. I owe you a beer, if your at the LUG next week ?<br>
><br>
><br>
> On 18 October 2010 21:26, David Holden <<a href="mailto:dh@iucr.org">dh@iucr.org</a><br>
</div><div><div></div><div class="h5">> <mailto:<a href="mailto:dh@iucr.org">dh@iucr.org</a>>> wrote:<br>
><br>
>     Hi Stuart,<br>
><br>
>      VERY quick hack but it may work, the grep allows # comments<br>
><br>
><br>
>     IFS=' ';<br>
><br>
>     datfile="1.dat"<br>
><br>
>     (<br>
>     cat $datfile | sort | grep -v \# | while read data<br>
>     do<br>
>      data_array=(`echo "$data"`)<br>
>      col1=${data_array[0]}<br>
>      echo -n "$col1 "<br>
>      cat $datfile  | sort  | grep "$col1" | awk '{print $2}' | tr '\n' ' '<br>
>      echo ""<br>
>     done<br>
>     ) | sort | uniq<br>
><br>
><br>
>     Dave.<br>
><br>
><br>
>     On 18/10/10 17:44, Stuart Burns wrote:<br>
>     > Hi everyone,<br>
>     ><br>
>     > I am hoping someone can help me a bit here. I am creating a cript that<br>
>     > deals with volume groups. However my bash skills fall short.<br>
>     ><br>
>     > I have a file that looks like this<br>
>     ><br>
>     > Vg955-01 /dev/diska1<br>
>     > Vg955-01 /dev/diska2<br>
>     > Vg978-01 /dev/disk45<br>
>     > Vg978-04 /dev/disk13<br>
>     ><br>
>     > You get the picture.<br>
>     ><br>
>     > Now what I am trying to do is get all the vg parts followed by the<br>
>     > constituent disks. Ie above should look like:<br>
>     ><br>
>     > Vg955-01 /dev/disk1a /dev/diska2<br>
>     > Vg978-01 /dev/disk45<br>
>     > Vg978-04 /dev/disk13<br>
>     ><br>
>     > I cant really think of an easy way to do it without resorting to perl.<br>
>     > Can anyone help?<br>
>     ><br>
>     > Regards<br>
>     ><br>
>     > Stu<br>
>     ><br>
>     > _______________________________________________<br>
>     > Chester mailing list<br>
</div></div>>     > <a href="mailto:Chester@mailman.lug.org.uk">Chester@mailman.lug.org.uk</a> <mailto:<a href="mailto:Chester@mailman.lug.org.uk">Chester@mailman.lug.org.uk</a>><br>
<div class="im">>     > <a href="https://mailman.lug.org.uk/mailman/listinfo/chester" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/chester</a><br>
>     ><br>
><br>
>     --<br>
</div>>     Dr David Holden. (<a href="mailto:dh@iucr.org">dh@iucr.org</a> <mailto:<a href="mailto:dh@iucr.org">dh@iucr.org</a>>)<br>
><br>
>     _______________________________________________<br>
>     Chester mailing list<br>
>     <a href="mailto:Chester@mailman.lug.org.uk">Chester@mailman.lug.org.uk</a> <mailto:<a href="mailto:Chester@mailman.lug.org.uk">Chester@mailman.lug.org.uk</a>><br>
<div><div></div><div class="h5">>     <a href="https://mailman.lug.org.uk/mailman/listinfo/chester" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/chester</a><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Chester mailing list<br>
> <a href="mailto:Chester@mailman.lug.org.uk">Chester@mailman.lug.org.uk</a><br>
> <a href="https://mailman.lug.org.uk/mailman/listinfo/chester" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/chester</a><br>
<br>
--<br>
Dr David Holden. (<a href="mailto:dh@iucr.org">dh@iucr.org</a>)<br>
<br>
_______________________________________________<br>
Chester mailing list<br>
<a href="mailto:Chester@mailman.lug.org.uk">Chester@mailman.lug.org.uk</a><br>
<a href="https://mailman.lug.org.uk/mailman/listinfo/chester" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/chester</a><br>
</div></div></blockquote></div><br>