Applescript or Terminal - String manipulation

Discussion in 'Mac Programming' started by Tinlad, Dec 14, 2006.

  1. macrumors member

    Joined:
    May 1, 2006
    Location:
    Nottingham, UK
    #1
    Hi, I've got a bit of a mental block.

    I'm writing a script for Salling Clicker using AppleScript that will allow me to mount/unmount the partitions on my external drive remotely.

    At the moment I have the name of the partition I want to unmount, "Mac Files", but I need the identifier, "disk1s1", which is the last six characters of the output from a shell script it runs:

    1: Apple_HFS Mac Files 162.9 GB disk1s1

    How can I use either AppleScript or some bash command to get those last six characters only? Using awk '{print $6}' to print only the sixth field only works if the partition doesn't have a space in the name.

    I hope that makes sense. Thanks in advance.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    $NF in awk is always the last field, no matter how many fields there are.
     
  3. thread starter macrumors member

    Joined:
    May 1, 2006
    Location:
    Nottingham, UK

Share This Page