resume_register.sh 600 Bytes
Newer Older
1 2
#!/bin/bash

3 4 5 6 7
path=$1
date=$2
filter=$3
column=$4

8 9 10 11
if [ "$#" -ne 4 ]; then
    echo "Usage $0 <path> <date> <filter> <column-name>"
    echo "Example: $0 ./tmp_201612 201612 MEC 2"
    exit
12 13
fi

14 15
input="${path}/${date}_Cadastro.csv"
output="${path}/${date}_Cadastro_Unique.csv"
16

17 18
head -n1 ${input} > $path/header.csv
iconv -f WINDOWS-1252 -t UTF-8 -o $path/tmp.csv $path/header.csv
19
columnId=$(sed s/${column}.*$/${column}/ $path/tmp.csv | sed -e 's/\t/\n/g' | wc -l)
20
rm -f $path/tmp.csv $path/header.csv
21

22
cmd="\$$columnId == \"${filter}\""
23
cat "${input}" | tr -d '\000' | awk -F $'\t' "$cmd" > "$output"