0

I have a list of files in UNIX environment:

I want to add two more column in each files for all rows.

Assume that I have 7 csv files (could be more or less)

Each files contain below nomenclature:

123;Peter;loaisa;45678998;
145;Jhon;Stugard;654123;

I would like to add info like this:

123;Peter;loaisa;45678998;09/12/2105;filename.csv
145;Jhon;Stugard;654123;09/12/2105;filename.csv

where the value "09/12/2105" is the date of the system with this format, and the value "filename.csv" is the name of the file.

To add these columns in each file I'm using the nex below command:

sed -i "s|$|;09/12/2015;ta_55eed97631073.csv|" ta_55eed97631073.csv

But I need to execute previous command for each file that I have in my folder, and sometimes there are a lot of files.

It's possible to modify this command to get the info of the date and file name from the O.S. and assign to this command? Or is there other way to do it?

2 Answers 2

1

for f in * ; do sed -i "s|$|;"$(date +%m/%d/%Y)";$f|" $f ; done

Sign up to request clarification or add additional context in comments.

Comments

0

awk to the rescue!

awk -vOFS=";" '{print $0,strftime("%m/%d/%Y"),FILENAME}' *.csv

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.