当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - 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

网友答案:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: