-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepareEvents.sh
executable file
·65 lines (56 loc) · 1.71 KB
/
prepareEvents.sh
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
# Starting time:
T="$(date +%s)"
# To remove any incomplete events from the end of the file
#echo "Removing incomplete events from the end of the file"
#python removeIncEvents.py
#echo "Counting Events in each file..."
#python Count_Events_LHEF.py
#echo "Splitting Files..."
#for lhe in $( ls *.lhe );
#do
# python splitLHE.py -i $lhe -n 50000
# rm $lhe
#done
# Ask for the file name prefix and also change extenstion from .lhe to .events
echo "Input the file name prefix: (e.g. user.cjohnson.powheg.w2jet.81514.txt._)"
read file_prefix
os_type=`uname`
if [[ "$os_type" == 'Darwin' ]]; then
last_line=`gtac $file |egrep -m 1 .`
rename 's/lhe/events/' *.lhe
else
last_line=`tac $file |egrep -m 1 .`
rename lhe events *.lhe
fi
# Add "</LesHouchesEvents>" to end of each file
# To Do: check if </LesHouchesEvents> is already the last line
for file in $( ls *.events )
do
if [[ "$last_line" != '</LesHouchesEvents>' ]]; then
echo "</LesHouchesEvents>" >> $file
fi
done
# Rename the file to use the prefix given earlier
#if [[ "$os_type" == 'Darwin' ]]; then
rename "s/pwgevents-/${file_prefix}/" pwgevents* # For Mac OS X
#else
# rename pwgevents- ${file_prefix} pwgevents* # For Linux
#fi
# Tarball individual .event file and name the tarball w/o the .events ext.
for file in $( ls *.events )
do
echo "Tarballing: " $file
name=${file%.events}
tar zcf ${name}.tar.gz $file
done
# Clean up and tarball into one neat package
#rm *.events
#echo "Tarballing the whole package"
#tar zcf events.tar.gz user.cjohnson*
#rm user.cjohnson*
# Finishing time:
T="$(($(date +%s)-T))"
# And display time:
echo "Time in seconds: ${T}"
printf "Formatted Time: %02d:%02d:%02d:%02d\n" "$((T/86400))" "$((T/3600%24))" "$((T/60%60))" "$((T%60))"