-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunite_wos_files
65 lines (46 loc) · 1.42 KB
/
unite_wos_files
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
#!/usr/bin/env bash
# unite_wos_files: Unite files exported from Web of Science
#
# Author: Helge Knüttel
# Date: 2019-2020
# Some sensible settings. Taken from https://kvz.io/bash-best-practices.html
set -o errexit # exit when a command fails
set -o pipefail # catch failing commands in a pipe
set -o nounset # exit when script tries to use undeclared variables
# set -o xtrace # Trace what gets executed. Useful for debugging.
# Help text
PrintHelp() {
cat << "EOF"
USAGE
unite_wos_files [FILE]...
unite_wos_files -h|--help
DESCRIPTION
Unite several export files from Web of Science into a single file
Web of Science allows to export bibliographic records only in portions of up to 500 records. This script will unite such files into a single one.
Output is written to STDOUT.
EXAMPLE
unite_wos_files WoS_other_reference_software_r*.txt > WoS_other_reference_software_records_combined.txt
EOF
}
case "$1" in
-h|--help )
PrintHelp
exit 0
;;
* )
# Just go on
;;
esac
HEADER="FN Clarivate Analytics Web of Science"
VERSION="VR 1.0"
ENDOFFILE="EF"
# Add byte order mark
# TODO: Endnote export files don't have a byte order mark. Will it hurt when importing into Endnote?
printf '\xEF\xBB\xBF%s\n' "$HEADER"
printf '%s\n' "$VERSION"
for file in "$@"
do
# There may be a byte-order mark before the header
sed -e "/${HEADER}/d" -e "/^${VERSION}/d" -e "/^${ENDOFFILE}/d" "$file"
done
printf '%s' "$ENDOFFILE"