I have a requirement to add carriage return at the end of each line in a CSV file that is available in a GCS bucket. I want to store the modified data in a new file in same GCS bucket. What we observed is though we are writing the data to new CSV file, it is overriding the original file.
Below is the code snippet that i am using for the task.
Can someone help me on how this can be achieved without changing the data in original file.
Thanks, Hemaraju
from google.cloud import storage
storage_client = storage.Client.from_service_account_json(r"C:\Users\XXXXX\Downloads\GCP-Key\XXXX.json")
bucket = storage_client.get_bucket('test-export-bucket-XXXX')
blob = bucket.blob('new/test_file.csv')
destination_blob = bucket.blob('test/modified_test_file.csv')
data = blob.download_as_string()
count = 0
for line in data.splitlines():
count +=1
print(line)
newline = line.decode('utf8') + '\r\n'
print(newline)
destination_blob.upload_from_string(newline)