查找具有default_track:1
(如果有)的字幕轨道,并输出轨道ID。在这种情况下,输出应为2
到目前为止,我有这个:
awk '/: subtitles.*default_track:1/ {gsub(".*Track ID ", "", $0); gsub(" .*", "", $0); print $0 }'
这给了我这个:
2:
但我正在寻找这个:
2
这是输入:
File 'v.mkv': container: Matroska [duration:71255000000 segment_uid:833ce3259a9891d7030fd4c31dd10a32 is_providing_timecodes:1]
Track ID 0: video (DIV3) [number:1 uid:1568461043394572035 codec_id:V_MS/VFW/FOURCC codec_private_length:40 codec_private_data:280000008002000060010000010018004449563300500a0000000000000000000000000000000000 language:und pixel_dimensions:640x352 display_dimensions:640x352 default_track:1 forced_track:0 enabled_track:1 default_duration:41708375 tag_bps:1278655 tag_duration:00\c01\c09.778000000 tag_number_of_frames:1673 tag_number_of_bytes:11152757 tag__statistics_writing_app:mkvmerge\sv7.3.0\s('Nouages')\s64bit\sbuilt\son\sNov\s30\s2014\s09\c21\c17 tag__statistics_writing_date_utc:2014-11-30\s08\c22\c46 tag__statistics_tags:BPS\sDURATION\sNUMBER_OF_FRAMES\sNUMBER_OF_BYTES]
Track ID 1: audio (MP3) [number:2 uid:15602440298129597552 codec_id:A_MPEG/L3 codec_private_length:0 language:und default_track:1 forced_track:0 enabled_track:1 default_duration:24000000 audio_sampling_frequency:48000 audio_channels:2 tag_bps:224451 tag_duration:00\c01\c09.768000000 tag_number_of_frames:2907 tag_number_of_bytes:1957440 tag__statistics_writing_app:mkvmerge\sv7.3.0\s('Nouages')\s64bit\sbuilt\son\sNov\s30\s2014\s09\c21\c17 tag__statistics_writing_date_utc:2014-11-30\s08\c22\c46 tag__statistics_tags:BPS\sDURATION\sNUMBER_OF_FRAMES\sNUMBER_OF_BYTES]
Track ID 2: subtitles (SubRip/SRT) [number:3 uid:7565148441499248899 codec_id:S_TEXT/UTF8 codec_private_length:0 language:und default_track:1 forced_track:0 enabled_track:1 tag_bps:79 tag_duration:00\c01\c06.555000000 tag_number_of_frames:18 tag_number_of_bytes:664 tag__statistics_writing_app:mkvmerge\sv7.3.0\s('Nouages')\s64bit\sbuilt\son\sNov\s30\s2014\s09\c21\c17 tag__statistics_writing_date_utc:2014-11-30\s08\c22\c46 tag__statistics_tags:BPS\sDURATION\sNUMBER_OF_FRAMES\sNUMBER_OF_BYTES]
Track ID 3: subtitles (SubRip/SRT) [number:4 uid:10370072232421497499 codec_id:S_TEXT/UTF8 codec_private_length:0 language:und default_track:0 forced_track:0 enabled_track:1 tag_bps:70 tag_duration:00\c01\c06.555000000 tag_number_of_frames:18 tag_number_of_bytes:590 tag__statistics_writing_app:mkvmerge\sv7.3.0\s('Nouages')\s64bit\sbuilt\son\sNov\s30\s2014\s09\c21\c17 tag__statistics_writing_date_utc:2014-11-30\s08\c22\c46 tag__statistics_tags:BPS\sDURATION\sNUMBER_OF_FRAMES\sNUMBER_OF_BYTES]
…
答案 0 :(得分:1)
这应该可以解决问题:
awk -F'[ :]+' '$4=="subtitles"&&/default_track:1[[:space:]]/{print $3}' yourfile
它将字段分隔符设置为包含:
。
PATTERN-part检查两件事:如果第四个字段等于字幕,如果default_track:1
在某行中。
答案 1 :(得分:0)
$ awk -F'[ :]' '/subtitles.*default_track:1/{print $3}' file
2
如果您的文件中包含subtitles
或default_track:1
的其他字符串,则用字边界围绕它们,例如用GNU awk:
$ awk -F'[ :]' '/\<subtitles\>.*\<default_track:1\>/{print $3}' file
2
答案 2 :(得分:0)
小+
解决了您的问题:
awk '/: subtitles.*default_track:1/ {print +$3}' file
2
使用+
会将0
添加到2:
。这只会获得价值。