Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

341
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!