-
Notifications
You must be signed in to change notification settings - Fork 1
/
concatenate.sh
31 lines (19 loc) · 929 Bytes
/
concatenate.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
#!/bin/bash
# bash script to concatenate all individual lyrics files from a single artist
# into a master lyrics file for that artist
# first argument is the artist directory name whose lyrics to concatenate
# check if a file exists with the same desired master lyrics file name
if [ -e data/$1_lyrics.txt ]; then
printf 'File %s already exists in the data directory.\n' $1_lyrics.txt
# if not, create the file and perform the concatenation
else
printf 'File %s does not exist in the data directory.\n' $1_lyrics.txt
# create master lyrics file for artist
touch data/$1_lyrics.txt
printf 'Empty text file %s created in the data directory.\n' $1_lyrics.txt
#printf 'Concatenating %s files...' ls $1 | wc -l
# concatenate all files in artist's directory
cd lyrics/$1
cat $(ls -tr) >> ../../data/$1_lyrics.txt
printf 'Individual lyrics files successfully concatenated to /data/%s.\n' $1_lyrics.txt
fi