Re: mass manipulation within a CSV file
am 01.04.2008 05:12:54 von Jerry Stuckle
laredotornado wrote:
> Hi,
>
> I'm using PHP 5. I have a CSV file, whose absolute path is stored in
> $old_file_path. I want to generate a new file that is exactly like
> the old one, only that there is an "R-" inserted before the value in
> the second column (you can assume the file has at least two columns of
> non-empty data). What is the quickest way to do this?
>
> Thanks, - Dave
>
In this case I wouldn't even worry about it being a .csv file. I'd just
read it a line at a time (with fgets()), parse the line, insert the
value where I need it and write it back out.
Or, if this is a one-time occurrence, read it into a spreadsheet, create
a quick macro to do the conversion you wish, and save the file. I
wouldn't even use PHP (or any other programming language).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: mass manipulation within a CSV file
am 02.04.2008 18:00:28 von Janwillem Borleffs
laredotornado schreef:
> I'm using PHP 5. I have a CSV file, whose absolute path is stored in
> $old_file_path. I want to generate a new file that is exactly like
> the old one, only that there is an "R-" inserted before the value in
> the second column (you can assume the file has at least two columns of
> non-empty data). What is the quickest way to do this?
>
If you are working on a *nix environment and this is for one time use
only, simply use sed:
$ cat test.csv
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
foo,bar,uu,too
$ sed -E 's/,([^,]+)/,R-\1/' ./test.csv >> ./test-new.csv
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
foo,R-bar,uu,too
JW