How to copy a csv file contents and rewrite with additional array in the same file?

The Keeper

I have a one line csv file as below

table1, table_name //This is handled by one script 

I need to add another row as

table2, table_name //This is handled by another script 

Now, I want to add the table2 values without overwriting the table1 values in a csv file. So currently I'm doing

//for table1 in the same csv
$file = fopen('rowsCopied.csv', 'w+');
fputcsv($file, $row_write);
fclose($file);

//for table2 in the same csv
$file = fopen('anotherrowsCopied.csv', 'r');
$filecopy = fgetcsv($file);
fputcsv($file, $filecopy);
fclose($file);

I don't know how to proceed. Can someone help?

Chaitanya Maurya

Open the CSV file in "a+" mode and not in "w+" mode and then either directly append the rows or append a newline character first and then the CSV rows you want to add. Let me know if it helped

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to rewrite same file

From Dev

Sed to copy part of file name into another contents of file with same substring

From Dev

CSV file contents to two dimensional array

From Dev

How to copy NSData contents to temporary file?

From Dev

How to use `scp` command copy a folder while not rewrite the local file with same name?

From Dev

How to Search and Rewrite a CSV file using PHP?

From Dev

How to Search and Rewrite a CSV file using PHP?

From Dev

Saving dataframe and additional data in same .csv file with Pandas

From Dev

How do I copy contents of a file and concatenate it into a new file?

From Dev

MATLAB:How to copy contents from a file into a particular position of an old file

From Dev

How do I store contents of a file in an array?

From Dev

How to write the contents of my array in a text file?

From Dev

How do I store contents of a file in an array?

From Dev

copy the contents of a variable in a text file

From Java

How to copy from CSV file to PostgreSQL table with headers in CSV file?

From Dev

how to copy some csv file colums into another csv file with python?

From Dev

File contents into an array

From Dev

Array into a CSV file using same id in PHP

From Dev

How to make a copy of file in the same directory

From Dev

How to copy contents of one text file to another with reduced length?

From Dev

How to copy the contents of all files with a certain name into a new file?

From Dev

How to copy contents from one file to another word by word in C?

From Dev

How to copy file contents from remote server to local machine location?

From Dev

How to read csv file with additional comma in quotes using pyspark?

From Dev

Different contents for the same wav file

From Dev

Converting the contents of a CSV file into a dictionary

From Dev

Netsuite get CSV file contents

From Dev

How to copy contents of an array to a variable

From Dev

How to rewrite lines in file?

Related Related

  1. 1

    How to rewrite same file

  2. 2

    Sed to copy part of file name into another contents of file with same substring

  3. 3

    CSV file contents to two dimensional array

  4. 4

    How to copy NSData contents to temporary file?

  5. 5

    How to use `scp` command copy a folder while not rewrite the local file with same name?

  6. 6

    How to Search and Rewrite a CSV file using PHP?

  7. 7

    How to Search and Rewrite a CSV file using PHP?

  8. 8

    Saving dataframe and additional data in same .csv file with Pandas

  9. 9

    How do I copy contents of a file and concatenate it into a new file?

  10. 10

    MATLAB:How to copy contents from a file into a particular position of an old file

  11. 11

    How do I store contents of a file in an array?

  12. 12

    How to write the contents of my array in a text file?

  13. 13

    How do I store contents of a file in an array?

  14. 14

    copy the contents of a variable in a text file

  15. 15

    How to copy from CSV file to PostgreSQL table with headers in CSV file?

  16. 16

    how to copy some csv file colums into another csv file with python?

  17. 17

    File contents into an array

  18. 18

    Array into a CSV file using same id in PHP

  19. 19

    How to make a copy of file in the same directory

  20. 20

    How to copy contents of one text file to another with reduced length?

  21. 21

    How to copy the contents of all files with a certain name into a new file?

  22. 22

    How to copy contents from one file to another word by word in C?

  23. 23

    How to copy file contents from remote server to local machine location?

  24. 24

    How to read csv file with additional comma in quotes using pyspark?

  25. 25

    Different contents for the same wav file

  26. 26

    Converting the contents of a CSV file into a dictionary

  27. 27

    Netsuite get CSV file contents

  28. 28

    How to copy contents of an array to a variable

  29. 29

    How to rewrite lines in file?

HotTag

Archive