[Chester LUG] Help with a bash script

David Holden dh at iucr.org
Mon Oct 18 21:54:54 UTC 2010



On 18/10/10 22:29, Stuart Burns wrote:
> Dave,
> 
> Your right I do. If your going, I'm buying ;)
> 
> Stu

Extra incentive to make it this month then :)


Cheers,

 Dave.




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

-- 
Dr David Holden. (dh at iucr.org)




More information about the Chester mailing list