-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpand.sh
68 lines (60 loc) · 1.59 KB
/
expand.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
66
67
#!/bin/bash -
#===============================================================================
#
# FILE: expand.sh
#
# USAGE: ./expand.sh
#
# DESCRIPTION: Expand passed tar files
# 0) take in tar files and check for params
# 1) Create temp folder to expand to
# 2) Loop files to expand and retrieve first, last and email columns
# 3) Create a new output file with columns
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: DAVID MARILUCH (), [email protected]
# ORGANIZATION: WSU
# CREATED: 02/15/2017 01:25
# REVISION: ---
#===============================================================================
#set -o nounset # Treat unset variables as an error
# Help function with script usage
help ()
{
echo "Usage ./expand.sh [fileName1.tar.gz] [fileName2.tar.gz] [etc...]"
echo "Script can take any # of compressed tar files as params"
}
# Check for help call
if [[ $1 == "--help" ]]
then
help
exit 1
fi
# Check if directory exists
dir="$PWD/tmp"
echo "Checking if $dir exists"
if [[ -d $dir ]]
then
echo "$dir exists"
else
echo "$dir doesn't exist"
echo "creating directory"
mkdir -p $dir
fi
# For each compressed file passed as param expand into $PWD/tmp
for filename in *.tar.gz
do
echo "Expanding $filename"
tar -zxvf $filename -C $dir
done
# Loop over files in tmp
for file in $dir/*.csv
do
# awk to take values and append it to new output file
# calls filter.sh script to filter data and passes in the current .csv file ($file)
./filter.sh $file
done
exit 0