user3901666
user3901666

Reputation: 409

Populate a value in a particular column in csv

I have a folder where there are 50 excel sheets in CSV format. I have to populate a particular value say "XYZ" in the column I of all the sheets in that folder.

I am new to unix and have looked for a couple of pages Here and Here . Can anyone please provide me the sample script to begin with?

For example : Let's say column C in this case:

A             B        C
ASFD         2535
BDFG         64486
DFGC         336846   

I want to update column C to value "XYZ".

Thanks.

Upvotes: 0

Views: 136

Answers (1)

ennox
ennox

Reputation: 206

I would export those files into csv format - with semikolon as field separator - eventually by leaving out column descriptions (otherwise see comment below)

Then the following combination of SHELL and SED script could more or less do already the trick

#! /bin/sh

for i in *.csv
do
        sed -i -e "s/$/;XZY/" $i
done
  • -i means to edit the file in place, here you could append the value to all lines
  • -e specifies the regular expresssion for substitution

You might want to use a similar script like this, to rename "XYZ" to "C" only in the 1st line if the csv files should contain also column descriptions.

Upvotes: 1

Related Questions