-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_records_oxford.sh
More file actions
executable file
·55 lines (33 loc) · 1.04 KB
/
merge_records_oxford.sh
File metadata and controls
executable file
·55 lines (33 loc) · 1.04 KB
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
#!/bin/bash
COUNTER=0
if [ $# -ne 2 ]
then
echo "Usage: $0 SOURCE_DIRECTORY TARGET_DIRECTORY"
exit 1
else
SOURCE_DIRECTORY=$1
TARGET_DIRECTORY=$2
fi
function merge_records ()
{ # merge all the xml files of a subdirectory like 1213/.
while read directory; do
cd $directory
echo $COUNTER merge directory "$directory"
filename="$TARGET_DIRECTORY"oxford-"$directory".xml
find . -name *.xml -exec cat {} \; > $filename
cd ..
#remove xml declaration
sed -e 's/<?xml[^>]*?>//g' -i $filename
#remove doctype declaration (may be split over two lines)
sed -e 's/<!DOCTYPE[^>]*>\{0,1\}//g' -i $filename
sed -e 's/.*shing.*dtd">//g' -i $filename
#add xml declaration at the beginning and root tag
sed -e '1i<collection>' -i $filename
sed -e '1i<?xml version=\"1.0\" encoding=\"UTF-8\" ?>' -i $filename
echo "</collection>" >> $filename
let COUNTER=COUNTER+1
done
}
cd $SOURCE_DIRECTORY
ls -A | merge_records
#cat /home/lionel/Documents/swissbib/git_repo/analysis/shell/directory_redo.txt | merge_records