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

时间:2015-05-24 21:28:15

标签: linux bash csv

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

1 个答案:

答案 0 :(得分:1)

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