T
T
Tiamon2020-10-25 16:15:00
bash
Tiamon, 2020-10-25 16:15:00

How to replace a character in csv in a column?

Your help is urgently needed. Need in a csv file of the form:

2597;2597;;   ;"008000000";"";Hager (Deutschland);"Kugeldrehvorrich...";660,09;auf Anfrage;"Maschinen>Vorrichtungen>Ku...";


Replace in the ninth column (and only in it ;660 , 09; ) the character "," (comma) with a dot in all lines.

Suitable for any programming language that can be run on linux by krone, if a ready-made version is available. Unfortunately, there is no time to figure it out on your own, but you need it urgently. ((((I'm ready to throw a beer for help)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hint000, 2020-10-26
@Tiamon

Oh holy saints, in the answers there are some sheets of python code ...

awk 'BEGIN{FS=OFS=";"} {gsub(/\,/, ".", $9)} 1' имяфайла.csv > новыйфайл.csv

copy- paste from here: https://unix.stackexchange.com/questions/492500/aw...
only there, on the contrary, the dot was changed to a comma

Y
youngtitanium, 2020-10-25
@youngtitanium

Language: python

filename = '' # туты имя файла пишешь

with open(filename, 'r', encoding='utf8') as f:
    lines = f.readlines()
newlines = []
for data in lines:
    data = data.split(';')
    data[8] = data[8].replace(',', '.')
    data = ';'.join(data)
    newlines.append(data)
with open(filename, 'w') as f:
    f.write(newlines)

The code itself will open the file, replace the line and save it!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question