Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

343
Visualizações
How to pad CSV file missing columns

I have a problem with some CSV files comming from a soft and that I want to use to make PostgreSQL import (function COPY FROM CSV). The problem is that some last columns are missing like this (letter for headers, number for values, _ for the TAB delimiter):

a_b_c_d
1_2_3_4
5_6_7       <- last column missing
8_9_0_1
2_6_7       <- last column missing

COPY in_my_table FROM file.csv result is : ERROR: missing data for column "d"

Sample of a correct file for import :

a_b_c_d
1_2_3_4
5_6_7_       <- null column but not missing
8_9_0_1
2_6_7_       <- null column but not missing

My question : is there some commands in bash / linux shell to add the TAB delimiter to make a correct / comlete / padded csv file with all columns.

Thanks for help.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Ok, so in fact I found this:

awk -F'\t' -v OFS='\t' 'NF=50' input.csv > output.csv 

where 50 is the number of TAB + 1.

over 4 years ago · Santiago Trujillo Relatório

0

Don't knew much about linux but this could be easily done in postgresql via simple command like

copy tableName from '/filepath/name.csv' delimiter '_' csv WITH NULL AS 'null';
over 4 years ago · Santiago Trujillo Relatório

0

You can use a combination of sed and regular expressions:

sed -r 's/^[0-9](_[0-9]){2}$/\0_/g' file.csv

You only need to replace _ by your delimiter (\t).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda