shell script

13. Resolução

Juliano Güntzel Melo
JulianoMelo

(usa Outra)

Enviado em 24/08/2020 - 19:26h

Desenvolvi esse código para resolver o meu problema.

#/bin/bash
echo "" > datasetorganizado.txt
cat dataset.csv | awk -F"," '{print $1,$2,$3,$4}' | tail -8768 > manipulado.txt
cat manipulado.txt | head -1 > organizador.txt
vP=2
vColunas=`cat dataset.csv | head -1 | awk -F"," '{print $1,$2,$3,$4}'`
while [ $vP -ne 8770 ];
do
echo "$vColunas" >> datasetorganizado.txt
vC=1
while [ $vC -ne 24 ];
do
cat manipulado.txt | head -$vP | tail -1 >> organizador.txt
vC=$((vC+1))
vP=$((vP+1))
done
sort organizador.txt >> datasetorganizado.txt
echo "" > organizador.txt
echo "" >> datasetorganizado.txt
echo "" >> datasetorganizado.txt
done
cat datasetorganizado.txt


  


14. Re: shell script

Mauriciodez
Mauriciodez

(usa Debian)

Enviado em 24/08/2020 - 20:16h

V aí se te serve

mauricio@phantom ~/Desktop $ cat 1.txt 
A803,06/03/2018,23,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,06/03/2018,04,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,07/03/2018,05,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,01/03/2018,06,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,01/03/2018,07,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,01/03/2018,08,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,06/03/2018,09,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,18/03/2018,10,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,18/03/2018,11,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,12/03/2018,12,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,11/03/2018,13,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,11/03/2018,14,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,08/03/2018,15,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,08/03/2018,16,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,08/03/2018,17,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,08/03/2018,18,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
A803,08/03/2018,00,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////,////
mauricio@phantom ~/Desktop $ cat 1.txt | sort -k1,2 -k2,3 | cut -d',' -f1-3
A803,01/03/2018,06
A803,01/03/2018,07
A803,01/03/2018,08
A803,06/03/2018,04
A803,06/03/2018,09
A803,06/03/2018,23
A803,07/03/2018,05
A803,08/03/2018,00
A803,08/03/2018,15
A803,08/03/2018,16
A803,08/03/2018,17
A803,08/03/2018,18
A803,11/03/2018,13
A803,11/03/2018,14
A803,12/03/2018,12
A803,18/03/2018,10
A803,18/03/2018,11
mauricio@phantom ~/Desktop $



------------------------------------------------------| Linux User #621728 |------------------------------------------------------

" Nem sempre é amigo aquele que te tira do buraco !!! ( Saddam Hussein )"

------------------------------------------------------| Linux User #621728 |------------------------------------------------------




15. Re: shell script

Marcelo Oliver
msoliver

(usa Debian)

Enviado em 24/08/2020 - 23:00h

JulianoMelo escreveu:

Desenvolvi esse código para resolver o meu problema.

#/bin/bash
echo "" > datasetorganizado.txt
cat dataset.csv | awk -F"," '{print $1,$2,$3,$4}' | tail -8768 > manipulado.txt
cat manipulado.txt | head -1 > organizador.txt
vP=2
vColunas=`cat dataset.csv | head -1 | awk -F"," '{print $1,$2,$3,$4}'`
while [ $vP -ne 8770 ];
do
echo "$vColunas" >> datasetorganizado.txt
vC=1
while [ $vC -ne 24 ];
do
cat manipulado.txt | head -$vP | tail -1 >> organizador.txt
vC=$((vC+1))
vP=$((vP+1))
done
sort organizador.txt >> datasetorganizado.txt
echo "" > organizador.txt
echo "" >> datasetorganizado.txt
echo "" >> datasetorganizado.txt
done
cat datasetorganizado.txt

Segue:


tit=$(sed -n '1p' webkit.txt |cut -d',' -f1-3) #salva o titulo
sed '1d' webkit.txt|awk -F '[,/]' '{uts=mktime($4" "$3" "$2" "$5" ""00 00");print $1","$2"/"$3"/"$4","$5","uts}'|sort -t"," -k4 > ordenado.txt
sed '/1s/^.*&/${tit}\n&/' ordenado.txt #repõe o titulo


______________________________________________________________________
Importante: echo -e "\n$(lynx --dump goo.gl/a9KeFc|sed -nr '/^[ ]+Se/,/dou.$/p')\n"
Att.: Marcelo Oliver
______________________________________________________________________


16. Resolvido

Juliano Güntzel Melo
JulianoMelo

(usa Outra)

Enviado em 26/08/2020 - 12:31h

echo "" > datasetorganizado.txt
cat dataset.csv | awk -F"," '{print $1,$2,$3,$4}' | tail -8768 > manipulado.txt
cat manipulado.txt | head -1 > organizador.txt
nano organiza.sh
#/bin/bash
vP=2
vD=`cat manipulado.txt | head -1 | awk '{print $2}'`
vT=`cat manipulado.txt | head -1 | awk '{print $2}'`
vS=`cat manipulado.txt | head -8769 | tail -1 | awk '{print $2}'`
vColunas=`cat dataset.csv | head -1 | awk -F"," '{print $1,$2,$3,$4}'`
while [ $vS != 0 ];
do
echo "$vColunas" >> datasetorganizado.txt
if [ $vD == $vS ]; then
vS=0
fi
while [ $vD == $vT ];
do
cat manipulado.txt | head -$vP | tail -1 >> organizador.txt
vP=$((vP+1))
echo "$vP / 8769"
vD=`cat manipulado.txt | head -$vP | tail -1 | awk '{print $2}'`
if [ $vP == 8769 ]; then
vD=0
fi
done
vT=`cat manipulado.txt | head -$vP | tail -1 | awk '{print $2}'`
sort organizador.txt >> datasetorganizado.txt
echo "" > organizador.txt
echo "" >> datasetorganizado.txt
echo "" >> datasetorganizado.txt
done
#Ctrl+x (y)enter
chmod +x organiza.sh
./organiza.sh

#Teste:
cat datasetorganizado.txt
#codigo_estacao data hora temp_inst

#A803 06/03/2018 00 ////
#A803 06/03/2018 01 ////
#A803 06/03/2018 02 ////
#A803 06/03/2018 03 ////
#A803 06/03/2018 04 ////
#A803 06/03/2018 05 ////
#A803 06/03/2018 06 ////
#A803 06/03/2018 07 ////
#A803 06/03/2018 08 ////
#A803 06/03/2018 09 ////
#A803 06/03/2018 10 ////
#A803 06/03/2018 11 ////
#A803 06/03/2018 12 ////
#A803 06/03/2018 13 ////
#A803 06/03/2018 14 ////
#A803 06/03/2018 15 ////
#A803 06/03/2018 16 ////
#A803 06/03/2018 17 ////
#A803 06/03/2018 18 ////
#A803 06/03/2018 19 ////
#A803 06/03/2018 20 ////
#A803 06/03/2018 21 ////
#A803 06/03/2018 22 ////
#A803 06/03/2018 23 ////...
#...
#...codigo_estacao data hora temp_inst
#A803 06/03/2019 00 26.8
#A803 06/03/2019 01 25.3
#A803 06/03/2019 02 24.1
#A803 06/03/2019 03 23.4
#A803 06/03/2019 04 23.3
#A803 06/03/2019 05 23.7
#A803 06/03/2019 06 23.1
#A803 06/03/2019 07 22.7
#A803 06/03/2019 08 23.0
#A803 06/03/2019 09 21.7
#A803 06/03/2019 10 21.8
#A803 06/03/2019 11 22.0
#A803 06/03/2019 12 23.1
#A803 06/03/2019 13 25.0
#A803 06/03/2019 14 26.0
#A803 06/03/2019 15 28.3
#A803 06/03/2019 16 30.4
#A803 06/03/2019 17 30.1
#A803 06/03/2019 18 28.5
#A803 06/03/2019 19 25.6
#A803 06/03/2019 20 25.1
#A803 06/03/2019 21 25.1



01 02



Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts