split_sample.sh 1.39 KB
Newer Older
Roland Levillain's avatar
Roland Levillain committed
1
# /bin/sh
Guillaume Lazzara's avatar
Guillaume Lazzara committed
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Copyright (C) 2008, 2009, 2010 EPITA Research and Development
# Laboratory (LRDE).
#
# This file is part of Olena.
#
# Olena is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, version 2 of the License.
#
# Olena is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Olena.  If not, see <http://www.gnu.org/licenses/>.

20
21
if ! [ $# -eq 4 ]; then
  echo "Usage: $0 <file1> <file extension> <suffix> <dst dir>"
Guillaume Lazzara's avatar
Guillaume Lazzara committed
22
23
24
25
26
27
  exit 1;
fi

begins=`grep -n -R '//[[:space:]]*\\\{' $1 | cut -d ':' -f 1`
ends=`grep -n -R '//[[:space:]]*\\\}' $1 | cut -d ':' -f 1`

28
29
30
31
if ! [ -z "$3" ]; then
  suffix=".$3"
fi

Roland Levillain's avatar
Roland Levillain committed
32
split=false
33
i=0
Guillaume Lazzara's avatar
Guillaume Lazzara committed
34
for begin in $begins; do
35
  i=$((i+1))
Guillaume Lazzara's avatar
Guillaume Lazzara committed
36
  partend=$((`echo $ends | cut -d ' ' -f $i` - 1))
Guillaume Lazzara's avatar
Guillaume Lazzara committed
37
  subdir=`basename \`dirname $1\``
38
  out_name="`basename $1 .$2`-$i.$2$suffix"
Guillaume Lazzara's avatar
Guillaume Lazzara committed
39
40
41
  if [ "$subdir" != "examples" ] && [ "$subdir" != "outputs" ]; then
    out_name="${subdir}_$out_name"
  fi
42
  head -n $partend $1 | tail -n $(($partend - $begin)) > "$4/$out_name"
Roland Levillain's avatar
Roland Levillain committed
43
  split=true
Guillaume Lazzara's avatar
Guillaume Lazzara committed
44
45
done

Roland Levillain's avatar
Roland Levillain committed
46
if [ $split ] && [ $i -gt 1 ]; then
47
  echo "* $1 has been split in $i files."
Guillaume Lazzara's avatar
Guillaume Lazzara committed
48
fi