Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- file=$1
- tmp="/tmp/$$.tmp"
- function insert_header() {
- sed '1s/$/#'"$1"'/g' "$file" > "$tmp"
- cat "$tmp" > "$file"
- head -1 "$file" > "$tmp"
- }
- for var in $(cat "$file" | cut -f 12 -d "#" | tr -d '"' | grep -Eo '\|[0-9|A-Z]+' | tr -d '|' | sort -u) ; do
- echo -n "Processando variável ${var}..."
- insert_header $var
- while read linha ; do
- count=$(echo $linha | grep -Eo "\|${var}+\|[^0-9 ;A-Z)]+[0-9A-Z]+" | tr -d '|' | sed 's/<>/=/g' | cut -f 2 -d "=" | wc -l)
- if [[ "$count" -eq "0" ]] ; then
- echo "${linha}#"
- else
- while read val ; do
- echo "${linha}#${val}"
- done < <(echo $linha | grep -Eo "\|${var}+\|[^0-9 ;A-Z)]+[0-9A-Z]+" | tr -d '|' | sed 's/<>/=/g' | cut -f 2 -d "=")
- fi
- done < <(tail -n +2 "$file") >> "$tmp"
- cat "$tmp" > "$file"
- echo " OK"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement