File size: 1,378 Bytes
9ae74ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash

tags=""

#https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable
trim() {
    local var="$*"
    # remove leading whitespace characters
    var="${var#"${var%%[![:space:]]*}"}"
    # remove trailing whitespace characters
    var="${var%"${var##*[![:space:]]}"}"   
    echo -n "$var"
}


#https://stackoverflow.com/questions/19408649/pipe-input-into-a-script
if [ -p /dev/stdin ]; then
    while IFS= read tag; do
        tags="$tags $(trim $tag)"
    done

fi



if [ $# -eq 0 ]; then
    echo >&2 ""
    echo >&2 "silentextractspecific by bcov - a tool to easily extract specific tags from silent files"
    echo >&2 "Usage:"
    echo >&2 "        cat list_of_tags.list | silentextractspecific myfile.silent"
    echo >&2 "                             or"
    echo >&2 "        silentextractspecific myfile.silent tag1 tag2 tag3"
    echo >&2 "Flags:"
    echo >&2 "        -j cpus"
    echo >&2 "        -p param_file"
    echo >&2 "        @flags_file"
    exit 1
fi


source $(dirname $(type -p "$0"))/_helpers/extract_flags.sh

silent=$1
shift
for tag in "$@"; do
    tags="$tags $(trim $tag)"
done


if [ -z "$tags" ]; then
    exit 0;
fi


tmp_file=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
tmp_file="tmp_${tmp_file}.silent"

echo "$tags" | silentslice $silent > $tmp_file

silentextract $tmp_file

rm $tmp_file