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

3 4 5 6
if [ "$#" -ne 4 ]; then
    echo "Usage $0 <path> <date> <filter> <column-name>"
    echo "Example: $0 ./tmp_201612 201612 MEC 2"
    exit
7 8
fi

9 10 11 12
path=$1
date=$2
filter=$3

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

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

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