Results 1 to 3 of 3

Thread: BASH scripting Multiple Variables

  1. #1
    Join Date
    Jun 2009
    Beans
    18

    BASH scripting Multiple Variables

    I'm working on a script that will have a few goals.


    1. That it will read all attachments from a MKV file and get the attachment ID and store on a variable
    2. That it will get the name from the attachment and store in a second variable
    3. That it will check attachment name to see if the TTF file already exists in my font cache directory. If so, do nothing, if not, extract and move the file to my cache directory.


    I don't want to constantly extract all the fonts if they already exist, but I am by no means a BASH guru and am trying to expand my skills. Can someone help? Attached below is my relevant scriptlet.


    Code:
    for f in *.mkv
    do
      attachments=$(mkvmerge --identify TEST.mkv | grep Attachment | awk -F " " '{print $3}' | sed 's/://g' )
      fontname=$(mkvmerge --identify TEST.mkv | grep Attachment | awk -F "'" '{print $4}')
    
      #Here is the part that I can't figure out. Let me know what you think
    
      for font in $attachments && for name in $fontname;
        do
          echo 'Extract attachment $font from $f'
          mkvextract attachments "$f" $attachments
          echo "$fontname"
          sleep 30
      done
    done
    
    sudo fc-cache -fv
    Last edited by gachnar; February 25th, 2013 at 01:27 AM.

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,326
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: BASH scripting Multiple Variables

    Code:
    #!/bin/bash
    
    for f in *.mkv
    do
      while read a_id font
      do
        echo "Extract attachment #$a_id ($font) from $f"
        mkvextract attachments "$f" "$a_id"
      done < <( mkvmerge --identify "$f" | sed -rn "/Attachment/ s/.*([0-9]+):.*'(.*)'/\1 \2/p" )
    done
    Last edited by Vaphell; February 25th, 2013 at 04:47 AM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Jun 2009
    Beans
    18

    Re: BASH scripting Multiple Variables

    Thanks for that. I have had a long day and will test that here shortly and report back.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •