Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding field/column to a CSV file

Status
Not open for further replies.

arun10427

Programmer
Oct 24, 2009
29
US
Hey all,
Can someone tell me how I could add field/column to a CSV file?
 
Hello

- Read the CSV file in line by line.
- Change one line at a time to include the new field/column.
- Append one line at a time to a new CSV file.
- At the end rename the new CSV file.

Chris
 
Do as Zhris says, but use Text::CSV_XS to parse the file...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Hi

arun10427 said:
how I could add field/column to a CSV file?
Taking the problem as simple as you described it, there is no need to parse the file :
Code:
perl -i -pe 's/$/,new/' file.csv
Of course, a more detailed description of the task may affect the solutions we suggest...

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top