shaveax
shaveax

Reputation: 478

How to add specific information in a csv file in specific row and column?

I have a script in bash that in some part of the code i need to add to a csv specific information in row and column specific, for example :

The format of my csv is the next :

Columns1 Columns2 Columns3 Columns4 Columns5 Columns6 Columns7 Columns8
animals   value2   value3   value4   value5   value6   value7   value8
bird      value2   value3   value4   value5   value6   value7   value8

So, I need that when the script found a value for example :

grep "animals" myfile.csv

add some information for example in the row with the value "animals" add or replace the value in the column5

In all my script.sh always I need to add several information many times in a specific range.

I would appreciate that the solution was in bash

Upvotes: 0

Views: 423

Answers (1)

user554538
user554538

Reputation:

You can do this very easily with awk:

awk -v M=match -v R=replace 'BEGIN {FS=","; OFS=","} $1==M {$5=R} {print}' infile.csv > outfile.csv

Upvotes: 1

Related Questions