shell script

1. shell script

Juliano Güntzel Melo
JulianoMelo

(usa Outra)

Enviado em 18/08/2020 - 16:59h

Desenvolver um shell script que leia o arquivo dataset.csv com dados de uma estação meteorológica, e mostre de forma automática, 4 informações pertinentes retiradas do .csv, de forma organizada. Como faço isso?

O arquivo tem mais de 8 mil linhas, vou mandar as primeiras linhas do arquivo dataset.csv para vocês dar uma olhada.

codigo_estacao,data,hora,temp_inst,temp_max,temp_min,umid_inst,umid_max,umid_min
,pto_orvalho_inst,pto_orvalho_max,pto_orvalho_min,pressao,pressao_max,pressao_mi
n,vento_vel,vento_direcao,vento_rajada,radiacao,precipitacao
A803,06/03/2018,23,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
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,00,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,19,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,20,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,21,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,22,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,01,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,02,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,03,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,07/03/2018,04,19.0,19.9,19.0,////,////,////,////,////,////,1002.2,1002.3,10
02.0,1.5,80,4.6,-3.54,0.0
A803,07/03/2018,05,17.9,19.0,17.9,////,////,////,////,////,////,1001.9,1002.2,10
01.9,1.1,91,3.7,-3.54,0.0
A803,07/03/2018,06,17.9,17.9,17.5,////,////,////,////,////,////,1002.1,1002.1,10
01.9,1.1,113,2.8,-3.47,0.0
A803,07/03/2018,07,16.8,17.9,16.8,////,////,////,////,////,////,1002.0,1002.2,10
01.9,0.6,107,2.9,-3.48,0.0
A803,07/03/2018,08,16.6,17.0,16.5,////,////,////,////,////,////,1002.6,1002.6,10
02.0,1.7,142,3.0,-3.50,0.0
A803,07/03/2018,09,16.1,16.6,16.1,////,////,////,////,////,////,1003.0,1003.0,10
02.5,1.4,113,3.5,-3.54,0.0
A803,07/03/2018,10,15.2,16.1,15.1,////,////,////,////,////,////,1003.6,1003.6,10
03.0,1.2,145,3.5,53.16,0.0
A803,07/03/2018,11,17.8,17.9,15.2,////,////,////,////,////,////,1004.2,1004.2,10
03.6,1.2,97,2.9,619.1,0.0
A803,07/03/2018,12,19.6,19.6,17.8,////,////,////,////,////,////,1004.4,1004.4,10
04.2,1.3,67,3.8,1449.,0.0
A803,07/03/2018,13,21.1,21.3,19.5,////,////,////,////,////,////,1004.6,1004.7,10
04.4,1.7,145,3.7,2228.,0.0
A803,07/03/2018,00,22.6,23.7,22.6,////,////,////,////,////,////,1001.1,1001.1,10
00.5,1.1,108,2.7,-3.54,0.0
A803,07/03/2018,14,23.0,23.1,21.0,////,////,////,////,////,////,1004.4,1004.7,10
04.4,2.0,113,6.7,2828.,0.0
A803,07/03/2018,23,20.4,22.9,20.4,////,////,////,////,////,////,1002.1,1002.1,10
01.8,1.2,41,2.0,8.256,0.0
A803,07/03/2018,15,23.4,23.6,22.9,////,////,////,////,////,////,1003.6,1004.4,10
03.6,2.4,165,5.8,3261.,0.0
A803,07/03/2018,16,23.9,24.5,23.4,////,////,////,////,////,////,1003.1,1003.6,10
03.1,2.6,216,5.9,3442.,0.0
A803,07/03/2018,17,25.1,25.3,23.9,////,////,////,////,////,////,1002.6,1003.1,10
02.6,2.3,229,5.3,3375.,0.0
A803,07/03/2018,01,21.6,22.6,21.6,////,////,////,////,////,////,1001.6,1001.6,10
01.1,1.7,128,3.8,-3.54,0.0
A803,07/03/2018,18,26.1,26.1,24.9,////,////,////,////,////,////,1002.0,1002.6,10
01.9,1.5,130,5.2,3060.,0.0
A803,07/03/2018,19,26.5,26.5,25.3,////,////,////,////,////,////,1001.5,1001.9,10
01.5,1.7,126,5.7,2546.,0.0
A803,07/03/2018,02,20.9,21.6,20.9,////,////,////,////,////,////,1002.1,1002.1,10
01.6,1.7,122,5.6,-3.54,0.0
A803,07/03/2018,20,26.3,26.6,25.9,////,////,////,////,////,////,1001.5,1001.5,10
01.4,1.7,114,5.4,1856.,0.0
A803,07/03/2018,21,25.3,26.4,25.3,////,////,////,////,////,////,1001.7,1001.7,10
01.5,2.0,67,4.1,1024.,0.0
A803,07/03/2018,22,22.9,25.4,22.9,////,////,////,////,////,////,1001.8,1001.8,10
01.6,1.1,49,3.7,181.2,0.0
A803,07/03/2018,03,19.9,20.9,19.9,////,////,////,////,////,////,1002.3,1002.4,10
02.1,1.7,112,5.6,-3.54,0.0


  


2. Re: shell script

Marcelo Oliver
msoliver

(usa Debian)

Enviado em 18/08/2020 - 20:02h


JulianoMelo escreveu:

Desenvolver um shell script que leia o arquivo dataset.csv com dados de uma estação meteorológica, e mostre de forma automática, 4 informações pertinentes retiradas do .csv, de forma organizada. Como faço isso?

O arquivo tem mais de 8 mil linhas, vou mandar as primeiras linhas do arquivo dataset.csv para vocês darem uma olhada.

codigo_estacao,data,hora,temp_inst,temp_max,temp_min,umid_inst,umid_max,umid_min
,pto_orvalho_inst,pto_orvalho_max,pto_orvalho_min,pressao,pressao_max,pressao_mi
n,vento_vel,vento_direcao,vento_rajada,radiacao,precipitacao
A803,06/03/2018,23,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
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,00,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,19,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,20,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,21,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,22,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,01,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,02,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,06/03/2018,03,////,////,////,////,////,////,////,////,////,////,////,////,/
///,////,////,////,////
A803,07/03/2018,04,19.0,19.9,19.0,////,////,////,////,////,////,1002.2,1002.3,10
02.0,1.5,80,4.6,-3.54,0.0
A803,07/03/2018,05,17.9,19.0,17.9,////,////,////,////,////,////,1001.9,1002.2,10
01.9,1.1,91,3.7,-3.54,0.0
A803,07/03/2018,06,17.9,17.9,17.5,////,////,////,////,////,////,1002.1,1002.1,10
01.9,1.1,113,2.8,-3.47,0.0
A803,07/03/2018,07,16.8,17.9,16.8,////,////,////,////,////,////,1002.0,1002.2,10
01.9,0.6,107,2.9,-3.48,0.0
A803,07/03/2018,08,16.6,17.0,16.5,////,////,////,////,////,////,1002.6,1002.6,10
02.0,1.7,142,3.0,-3.50,0.0
A803,07/03/2018,09,16.1,16.6,16.1,////,////,////,////,////,////,1003.0,1003.0,10
02.5,1.4,113,3.5,-3.54,0.0
A803,07/03/2018,10,15.2,16.1,15.1,////,////,////,////,////,////,1003.6,1003.6,10
03.0,1.2,145,3.5,53.16,0.0
A803,07/03/2018,11,17.8,17.9,15.2,////,////,////,////,////,////,1004.2,1004.2,10
03.6,1.2,97,2.9,619.1,0.0
A803,07/03/2018,12,19.6,19.6,17.8,////,////,////,////,////,////,1004.4,1004.4,10
04.2,1.3,67,3.8,1449.,0.0
A803,07/03/2018,13,21.1,21.3,19.5,////,////,////,////,////,////,1004.6,1004.7,10
04.4,1.7,145,3.7,2228.,0.0
A803,07/03/2018,00,22.6,23.7,22.6,////,////,////,////,////,////,1001.1,1001.1,10
00.5,1.1,108,2.7,-3.54,0.0
A803,07/03/2018,14,23.0,23.1,21.0,////,////,////,////,////,////,1004.4,1004.7,10
04.4,2.0,113,6.7,2828.,0.0
A803,07/03/2018,23,20.4,22.9,20.4,////,////,////,////,////,////,1002.1,1002.1,10
01.8,1.2,41,2.0,8.256,0.0
A803,07/03/2018,15,23.4,23.6,22.9,////,////,////,////,////,////,1003.6,1004.4,10
03.6,2.4,165,5.8,3261.,0.0
A803,07/03/2018,16,23.9,24.5,23.4,////,////,////,////,////,////,1003.1,1003.6,10
03.1,2.6,216,5.9,3442.,0.0
A803,07/03/2018,17,25.1,25.3,23.9,////,////,////,////,////,////,1002.6,1003.1,10
02.6,2.3,229,5.3,3375.,0.0
A803,07/03/2018,01,21.6,22.6,21.6,////,////,////,////,////,////,1001.6,1001.6,10
01.1,1.7,128,3.8,-3.54,0.0
A803,07/03/2018,18,26.1,26.1,24.9,////,////,////,////,////,////,1002.0,1002.6,10
01.9,1.5,130,5.2,3060.,0.0
A803,07/03/2018,19,26.5,26.5,25.3,////,////,////,////,////,////,1001.5,1001.9,10
01.5,1.7,126,5.7,2546.,0.0
A803,07/03/2018,02,20.9,21.6,20.9,////,////,////,////,////,////,1002.1,1002.1,10
01.6,1.7,122,5.6,-3.54,0.0
A803,07/03/2018,20,26.3,26.6,25.9,////,////,////,////,////,////,1001.5,1001.5,10
01.4,1.7,114,5.4,1856.,0.0
A803,07/03/2018,21,25.3,26.4,25.3,////,////,////,////,////,////,1001.7,1001.7,10
01.5,2.0,67,4.1,1024.,0.0
A803,07/03/2018,22,22.9,25.4,22.9,////,////,////,////,////,////,1001.8,1001.8,10
01.6,1.1,49,3.7,181.2,0.0
A803,07/03/2018,03,19.9,20.9,19.9,////,////,////,////,////,////,1002.3,1002.4,10
02.1,1.7,112,5.6,-3.54,0.0


Boa noite Juliano.
Quais são as " 4 informações pertinentes"?
O exemplo abaixo "printa" os campo de 01 a 04 de cada registro,
É o "básico" do awk.
awk -F"," '{print $1,$2,$3,$4}' estacoes.csv
Cada registro do arquivo de exemplo tem 20 "campos".....
A "formatação" está bem confusa...... com "quebras de linha nos registros".
Mas nada que o "comando SED" não possa resolver.....
______________________________________________________________________
Importante: echo -e "\n$(lynx --dump goo.gl/a9KeFc|sed -nr '/^[ ]+Se/,/dou.$/p')\n"
Att.: Marcelo Oliver
______________________________________________________________________


3. Re: shell script

Mauriciodez
Mauriciodez

(usa Debian)

Enviado em 18/08/2020 - 20:28h


opções não faltam
cut -d';' -f1-4 doc.csv 


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

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

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




4. shel script

Juliano Güntzel Melo
JulianoMelo

(usa Outra)

Enviado em 19/08/2020 - 08:21h

cat dataset.csv | tr [,] ' ' | awk '{print $1, $2, $3, $4}'

Eu coloquei essa linha de comando para separar as 4 informações, codigo_estacao data hora tem_inst, só faltou organizar por hora, como faço isso?

codigo_estacao data hora temp_inst
A803 06/03/2018 23 ////
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 00 ////
A803 06/03/2018 19 ////
A803 06/03/2018 20 ////
A803 06/03/2018 21 ////
A803 06/03/2018 22 ////
A803 06/03/2018 01 ////
A803 06/03/2018 02 ////
A803 06/03/2018 03 ////
A803 07/03/2018 04 19.0
A803 07/03/2018 05 17.9
A803 07/03/2018 06 17.9
A803 07/03/2018 07 16.8
A803 07/03/2018 08 16.6
A803 07/03/2018 09 16.1
A803 07/03/2018 10 15.2
A803 07/03/2018 11 17.8
A803 07/03/2018 12 19.6
A803 07/03/2018 13 21.1
A803 07/03/2018 00 22.6
A803 07/03/2018 14 23.0
A803 07/03/2018 23 20.4
A803 07/03/2018 15 23.4
A803 07/03/2018 16 23.9
A803 07/03/2018 17 25.1
A803 07/03/2018 01 21.6
A803 07/03/2018 18 26.1
A803 07/03/2018 19 26.5
A803 07/03/2018 02 20.9
A803 07/03/2018 20 26.3
A803 07/03/2018 21 25.3
A803 07/03/2018 22 22.9
A803 07/03/2018 03 19.9


5. Re: shell script

Mauriciodez
Mauriciodez

(usa Debian)

Enviado em 19/08/2020 - 13:31h

JulianoMelo escreveu:

Eu coloquei essa linha de comando para separar as 4 informações, codigo_estacao data hora tem_inst, só faltou organizar por hora, como faço isso?


Use o comando sort

EX
sort -k[numero_da_coluna] 


mair sobre o comando sort

man sort 

sort --help 


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

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

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




6. shel script

Juliano Güntzel Melo
JulianoMelo

(usa Outra)

Enviado em 19/08/2020 - 14:56h

cut -d',' -f1-4 dataset.csv | sort -k3

Coloquei essa linha de comando, até organizou um pouco as horas, porém deixou bagunçado as datas, preciso deixar as datas organizadas e as horas, como faço isso?

# cut -d',' -f1-4 dataset.csv | sort -k3
A803,01/01/2019,00,28.1
A803,01/01/2019,01,27.0
A803,01/01/2019,02,26.3
A803,01/01/2019,03,25.5
A803,01/01/2019,04,25.1
A803,01/01/2019,05,24.6
A803,01/01/2019,06,24.3
A803,01/01/2019,07,24.2
A803,01/01/2019,08,24.0
A803,01/01/2019,09,23.9
A803,01/01/2019,10,24.4
A803,01/01/2019,11,25.7
A803,01/01/2019,12,27.8
A803,01/01/2019,13,30.6
A803,01/01/2019,14,30.7
A803,01/01/2019,15,32.5
A803,01/01/2019,16,34.6
A803,01/01/2019,17,35.2
A803,01/01/2019,18,36.0...
...
...A803,31/10/2018,20,22.9
A803,31/10/2018,21,22.3
A803,31/10/2018,22,22.2
A803,31/10/2018,23,21.7
A803,31/12/2018,00,28.2
A803,31/12/2018,01,27.4
A803,31/12/2018,02,26.7
A803,31/12/2018,03,26.5
A803,31/12/2018,04,26.3
A803,31/12/2018,05,26.5
A803,31/12/2018,06,26.0
A803,31/12/2018,07,24.9
A803,31/12/2018,08,24.3
A803,31/12/2018,09,23.8
A803,31/12/2018,10,24.5
A803,31/12/2018,11,24.6
A803,31/12/2018,12,26.9
A803,31/12/2018,13,28.7
A803,31/12/2018,14,28.6
A803,31/12/2018,15,29.9
A803,31/12/2018,16,30.2
A803,31/12/2018,17,30.8
A803,31/12/2018,18,31.3
A803,31/12/2018,19,30.5
A803,31/12/2018,20,30.1
A803,31/12/2018,21,29.6
A803,31/12/2018,22,29.3
A803,31/12/2018,23,28.9
codigo_estacao,data,hora,temp_inst


7. Re: shell script

Marcelo Oliver
msoliver

(usa Debian)

Enviado em 19/08/2020 - 20:12h

JulianoMelo escreveu:

cut -d',' -f1-4 dataset.csv | sort -k3

Coloquei essa linha de comando, até organizou um pouco as horas, porém deixou bagunçado as datas, preciso deixar as datas organizadas e as horas, como faço isso?

# cut -d',' -f1-4 dataset.csv | sort -k3
A803,01/01/2019,00,28.1
A803,01/01/2019,01,27.0
A803,01/01/2019,02,26.3
A803,01/01/2019,03,25.5
A803,01/01/2019,04,25.1
A803,01/01/2019,05,24.6
A803,01/01/2019,06,24.3
A803,01/01/2019,07,24.2
A803,01/01/2019,08,24.0
A803,01/01/2019,09,23.9
A803,01/01/2019,10,24.4
A803,01/01/2019,11,25.7
A803,01/01/2019,12,27.8
A803,01/01/2019,13,30.6
A803,01/01/2019,14,30.7
A803,01/01/2019,15,32.5
A803,01/01/2019,16,34.6
A803,01/01/2019,17,35.2
A803,01/01/2019,18,36.0...
...
...A803,31/10/2018,20,22.9
A803,31/10/2018,21,22.3
A803,31/10/2018,22,22.2
A803,31/10/2018,23,21.7
A803,31/12/2018,00,28.2
A803,31/12/2018,01,27.4
A803,31/12/2018,02,26.7
A803,31/12/2018,03,26.5
A803,31/12/2018,04,26.3
A803,31/12/2018,05,26.5
A803,31/12/2018,06,26.0
A803,31/12/2018,07,24.9
A803,31/12/2018,08,24.3
A803,31/12/2018,09,23.8
A803,31/12/2018,10,24.5
A803,31/12/2018,11,24.6
A803,31/12/2018,12,26.9
A803,31/12/2018,13,28.7
A803,31/12/2018,14,28.6
A803,31/12/2018,15,29.9
A803,31/12/2018,16,30.2
A803,31/12/2018,17,30.8
A803,31/12/2018,18,31.3
A803,31/12/2018,19,30.5
A803,31/12/2018,20,30.1
A803,31/12/2018,21,29.6
A803,31/12/2018,22,29.3
A803,31/12/2018,23,28.9
codigo_estacao,data,hora,temp_inst


Boa noite.
Faltou um pequeno detalhe....
Informar para o "sort", qual é o separador de campo....
man sort|grep -E '^ +\-t'
-t, --field-separator=SEP

cut -d',' -f1-4 dataset.csv | sort -t"," -k3 


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


8. shell script

Juliano Güntzel Melo
JulianoMelo

(usa Outra)

Enviado em 20/08/2020 - 17:21h

cut -d',' -f1-4 dataset.csv | sort -t"," -k3

Usei essa linha de comando, mas não ficou legal, ficou mais bagunçado do que o arquivo original.
# cut -d',' -f1-4 dataset.csv | sort -t"," -k3
A803,06/03/2018,00,////
A803,10/07/2018,00,10.0
A803,23/08/2018,00,10.0
A803,04/07/2018,00,10.2
A803,07/08/2018,00,10.2
A803,10/08/2018,00,10.3
A803,08/06/2018,00,10.4
A803,26/05/2018,00,10.4
A803,24/07/2018,00,10.5
A803,26/06/2018,00,10.5
A803,20/06/2018,00,10.6
A803,27/07/2018,00,10.7
A803,23/06/2018,00,10.8
A803,25/06/2018,00,10.8
A803,28/07/2018,00,11.0
A803,05/09/2018,00,11.1
A803,11/08/2018,00,11.2
A803,16/08/2018,00,11.3
A803,30/07/2018,00,11.3...
...
...A803,16/06/2018,23,4.6
A803,17/06/2018,23,5.4
A803,15/06/2018,23,5.5
A803,21/07/2018,23,6.7
A803,03/06/2018,23,7.3
A803,14/06/2018,23,7.4
A803,23/05/2018,23,7.7
A803,13/06/2018,23,7.8
A803,26/08/2018,23,7.8
A803,10/07/2018,23,7.9
A803,06/06/2018,23,8.0
A803,20/08/2018,23,8.1
A803,18/06/2018,23,8.3
A803,25/08/2018,23,8.4
A803,08/06/2018,23,8.6
A803,12/07/2018,23,8.7
A803,24/05/2018,23,8.8
A803,05/08/2018,23,9.0
A803,11/07/2018,23,9.2
A803,30/07/2018,23,9.2
A803,02/06/2018,23,9.3
A803,31/07/2018,23,9.3
A803,04/07/2018,23,9.4
A803,20/07/2018,23,9.4
A803,21/08/2018,23,9.5
A803,01/08/2018,23,9.6
A803,26/06/2018,23,9.7
A803,22/05/2018,23,9.9
codigo_estacao,data,hora,temp_inst


9. Arquivo original

Juliano Güntzel Melo
JulianoMelo

(usa Outra)

Enviado em 20/08/2020 - 17:39h

Esse é o arquivo original, vou colocar no final como eu gostaria que ficasse, vou fazer de forma manual,
mas preciso descobrir uma forma de que isso seja feito automático, até porque o arquivo tem mais de 8 mil linhas
e não tem como eu organizar tudo manual.

# cut -d',' -f1-4 dataset.csv
codigo_estacao,data,hora,temp_inst
A803,06/03/2018,23,////
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,05/03/2019,01,26.1
A803,05/03/2019,00,25.3
A803,05/03/2019,09,23.1
A803,05/03/2019,03,24.9
A803,05/03/2019,21,29.5
A803,05/03/2019,13,28.5
A803,05/03/2019,06,23.1
A803,06/03/2019,09,21.7
A803,06/03/2019,17,30.1
A803,06/03/2019,21,25.1
A803,06/03/2019,14,26.0
A803,06/03/2019,05,23.7
A803,06/03/2019,19,25.6
A803,06/03/2019,10,21.8
A803,06/03/2019,13,25.0
A803,06/03/2019,18,28.5
A803,06/03/2019,00,26.8
A803,06/03/2019,01,25.3
A803,06/03/2019,16,30.4
A803,06/03/2019,07,22.7
A803,06/03/2019,02,24.1
A803,06/03/2019,15,28.3
A803,06/03/2019,04,23.3
A803,06/03/2019,06,23.1
A803,06/03/2019,08,23.0
A803,06/03/2019,12,23.1
A803,06/03/2019,03,23.4
A803,06/03/2019,11,22.0
A803,06/03/2019,20,25.1


Como tinha que ficar:

codigo_estacao,data,hora,temp_inst
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,23,////...
...
...A803,05/03/2019,00,25.3
A803,05/03/2019,01,26.1
A803,05/03/2019,03,24.9
A803,05/03/2019,06,23.1
A803,05/03/2019,09,23.1
A803,05/03/2019,13,28.5
A803,05/03/2019,21,29.5
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


10. Re: shell script

Marcelo Oliver
msoliver

(usa Debian)

Enviado em 20/08/2020 - 19:06h


JulianoMelo escreveu:

cut -d',' -f1-4 dataset.csv | sort -t"," -k3

Usei essa linha de comando, mas não ficou legal, ficou mais bagunçado do que o arquivo original.
# cut -d',' -f1-4 dataset.csv | sort -t"," -k3

Aqui funciona!!!!!
Ordena pelo campo 03, e os "títulos", na ultima linha.....
Se não quer os títulos na ultima linha,
faça uso do sed, ou do awk, para não casar a linha 1,
ou, para exclui-la do "sort", e, posteriormente, retorne-a!
Como já foi dito, existem muitas opções.....

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


11. shell script

Juliano Güntzel Melo
JulianoMelo

(usa Outra)

Enviado em 21/08/2020 - 14:49h

Eu queria desenvolver algo como um while, com a condição de enquanto estiver no mesmo dia, organize as linhas pela hora do dia, aí quando terminasse passasse para o próximo dia e assim por diante até chegar no último dia do arquivo.

Mas não sei muita coisa de shell script para poder montar toda essa estrutura.


12. Re: shell script

Marcelo Oliver
msoliver

(usa Debian)

Enviado em 22/08/2020 - 14:58h


JulianoMelo escreveu:

Eu queria desenvolver algo como um while, com a condição de enquanto estiver no mesmo dia, organize as linhas pela hora do dia, aí quando terminasse passasse para o próximo dia e assim por diante até chegar no último dia do arquivo.

Mas não sei muita coisa de shell script para poder montar toda essa estrutura.

Agora entendi...
Não é recomendado o while, o processo será muito moroso, visto que,
terá que "varrer" o arquivo inúmeras vezes.....
Exemplo:
Se o arquivo tem todos dias do Ano, serão 365 "whiles"......
Ao meu ver, o mais indicado é gerar as datas ("data hora"), em "Unix Time Stamp",
e ordenar.....
Dessa forma, é ordenado por data, hora.
Exemplo de data em "UTS"
echo "2020 08 22 13 58 30"|gawk '{uts=mktime($1" "$2" "$3" "$4" "$5" "$6);OFS=",";print $1,$2,$3,$4,$5,$6,uts}'
2020,08,22,13,58,30,1598115510

Com o date:
date -d"2020-08-22 18:00:00" +%s
date +%s
______________________________________________________________________
Importante: echo -e "\n$(lynx --dump goo.gl/a9KeFc|sed -nr '/^[ ]+Se/,/dou.$/p')\n"
Att.: Marcelo Oliver
______________________________________________________________________



01 02



Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner
Linux banner
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts