File: extractSC.bash

package info (click to toggle)
camitk 6.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 389,508 kB
  • sloc: cpp: 103,476; sh: 2,448; python: 1,618; xml: 984; makefile: 128; perl: 84; sed: 20
file content (46 lines) | stat: -rwxr-xr-x 1,354 bytes parent folder | download | duplicates (6)
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
#!/bin/bash
# extract a named structuralComponent or all structuralComponent from a pml
# Usage:
# extractSC.bash file.pml SCname
if [[ ($# -ne 1) && ($# -ne 2) ]] ; then
        echo "extractSC file.pml [SCname]"
        exit
fi

file=$1
base=${1/.pml/}
tmp=/tmp/$base.tmp

# extract line nr that match "structuralComponent" (odd line=start, even line=end)
grep -n structuralComponent $file > $tmp

index=1
nl="`wc -l $tmp | cut -f1 -d" "`"

while [ $index -lt $nl ]; do
    cmd=$index"p"
    lineStart=`sed -n $cmd $tmp | cut -f1 -d":"`
    indexEnd=`expr $index + 1`
    cmdEnd=$indexEnd"p"
    lineEnd=`sed -n $cmdEnd $tmp | cut -f1 -d":"`
    # extract name = everything after name=" up to the next "
    name=`sed -n $cmd $tmp | cut -f2 -d":" | grep "name" | cut -c2- | sed "s/.*name=\"\([^\"]*\).*/\1/g"`
    if [[ ((($# -eq 2) &&  ($name == $2)) || ($# -eq 1)) ]]; then
        if [ "$name" != "" ]; then
            out=$name.pml
        else
            out=sc-$index.pml
        fi;
        # test if file exists
        if [ -a "$out" ]; then
            out=$name-$index.pml
        fi
        out=`echo $out | sed "s/ /_/g" | sed "s/\//-/g"`
        echo $lineStart:$lineEnd \"$name\" saved in \"$out\"
        cmdExtract=$lineStart","$lineEnd"p"
        sed -n $cmdExtract $file > $out
    fi
    index=`expr $index + 2`
done

rm -rf $tmp