Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AWK print format help

I'm passing some text to awk to pull out a single value and pass it back to an Applescript. awk is finding two instances of the value and so I'm getting back the same value twice. I need it to just report one of these values. They will always be the same, so it doesn't matter which one I get back.


Here is the Applescript which asks awk to look for "timecode" in the text and extract the value after it:

set start_tc to do shell script "/usr/local/bin/ffmpeg -i" & movie_name_quoted_posix & "2>&1 | awk '$1 ~ /^timecode/ {print $NF}’ "


This is the text that gets passed to awk (you'll see the value "timecode" appears twice):


Metadata:

major_brand : qt

minor_version : 537199360

compatible_brands: qt

creation_time : 2015-03-31 14:39:26

timecode : 01:00:00:00

Duration: 00:01:04.08, start: 0.000000, bitrate: 37712 kb/s

Stream #0:0(eng): Video: dnxhd (AVdn / 0x6E645641), yuv422p, 1920x1080, 36175 kb/s, 24 fps, 24 tbr, 24k tbn, 24k tbc (default)

Metadata:

creation_time : 2015-03-31 14:39:26

handler_name : Apple Alias Data Handler

encoder : Avid DNxHD Codec

Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)

Metadata:

creation_time : 2015-03-31 14:39:26

handler_name : Apple Alias Data Handler

Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)

Metadata:

creation_time : 2015-03-31 14:41:09

handler_name : Apple Alias Data Handler

timecode : 01:00:00:00


The result I'm currently getting back is:


"01:00:00:00

01:00:00:00”


I need to result to be just one of these values, like this:


"01:00:00:00


I'm very new to awk. I believe I need to edit the {print $NF} part of the command, but I'm not having any luck so far.

Many thanks for any help anyone can offer.

Posted on Mar 31, 2015 11:12 AM

Reply
6 replies

AWK print format help

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.