aboutsummaryrefslogtreecommitdiff
path: root/extract-partened.sh
diff options
context:
space:
mode:
authorGabriel Hernan Czernikier <gaboherno@gmail.com>2014-10-12 16:05:15 -0300
committerGabriel Hernan Czernikier <gaboherno@gmail.com>2014-10-12 16:05:15 -0300
commit89891092a39ca411a20e4d1c105ed04079ef134d (patch)
treeb697f49b082b0554772179a0b968220c192440d4 /extract-partened.sh
parentfa6b243b08c2e483b8b6ed9654417607f158d416 (diff)
downloadvital-89891092a39ca411a20e4d1c105ed04079ef134d.tar.gz
vital-89891092a39ca411a20e4d1c105ed04079ef134d.tar.bz2
Initial commit of more TokensV2's functionality. Includes docummentation and license.
Diffstat (limited to 'extract-partened.sh')
-rw-r--r--extract-partened.sh107
1 files changed, 107 insertions, 0 deletions
diff --git a/extract-partened.sh b/extract-partened.sh
new file mode 100644
index 0000000..7c0ee4b
--- /dev/null
+++ b/extract-partened.sh
@@ -0,0 +1,107 @@
1#!/bin/bash
2 # usage:
3 # $1 input file
4 # $2 working directory
5
6
7# This file is part of TokensV2.
8#
9# TokensV2 is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# TokensV2 is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
21
22
23 help()
24 {
25 cat << eof
26 Usage: $0 [-n] files...
27
28 -n do nothing, only see what would be done
29 -R recursive (use find)
30 -h this message
31 files files to extract partened
32
33 Examples:
34 $0 -n * (see if everything is ok, then...)
35 $0 *
36
37 $0 -R .
38
39eof
40 }
41
42 while :
43 do
44 case "$1" in
45 -n)
46 apply_cmd='cat'
47 shift
48 ;;
49 -h) help ; exit 1 ;;
50 *) break ;;
51 esac
52 done
53
54 if [ -z "$1" ]; then
55 echo Usage: $0 [-h] [-n] [-R] files...
56 exit 1
57 fi
58
59 for my_line in `sed -n -r '
60
61 # matches header
62 /:/! h
63
64 /:/ {
65 x
66 G
67 s/^([^\n]*)\n(txt[^\n]*)\n(bin[^\n]*)$/\1\n\3\n\2/
68 s/(.*)\n(.*)\n(.*)\n(.*)/\1\n\3\n\4/
69 # save current contents
70 h
71 s/(.*)\n.*\ntxt: ([0-9]+) ([0-9]+)/\1,\2,\3,/p
72 }
73 ' $1`;
74 do
75 #line_ref=$my_line;
76 indice=`expr index "$my_line" ","`;
77 fileRef=${my_line:0:$indice-1};
78 my_line=${my_line:$indice};
79 indice=`expr index "$my_line" ","`;
80 iniPos=${my_line:0:$indice-1};
81 my_line=${my_line:$indice};
82 indice=`expr index "$my_line" ","`;
83 endPos=${my_line:0:$indice-1};
84 my_line=${my_line:$indice};
85
86 #echo "line: $line_ref $fileRef, $iniPos, $endPos, $((endPos-iniPos+1))";
87
88 if [ $((endPos-iniPos+1)) -ge 20 ]
89 then
90 #echo "File: $fileRef, Start: $iniPos, End: $endPos, Length: $((endPos-iniPos+1)).";
91 indext=`expr index "$fileRef" ".txt"`;
92 echo dd if=$2/$fileRef of="$2/${fileRef:0:$indext-1}-$iniPos-$endPos.txt" bs=1 skip=$((iniPos-1)) count=$((endPos-iniPos+1)) ;
93
94 dd if=$2/$fileRef of="$2/${fileRef:0:$indext-1}-$iniPos-$endPos.txt" bs=1 skip=$((iniPos-1)) count=$((endPos-iniPos+1)) ;
95 fi
96
97 done
98
99 exit 0;
100
101#TXT/a5364798.txt 1 100 $((100-1+1))
102#TXT/a5364798.txt 151 1050 $((1050-151+1))
103#TXT/a124124.txt 201 340 $((340-201+1))
104#TXT/a963455.txt 1 20 $((20-1+1))
105#TXT/a963455.txt 151 1000 $((1000-151+1))
106#TXT/a963455.txt 1005 1005 $((1005-1005+1))
107

Return to:

Send suggestions and report system problems to the System administrator.