I'm attempting to replace certain words (essentially the 2nd word of each line) in a text file, and then write them back out to either a new file, or overwrite the existing file.
I thought I was making progress, but when I went to write to a new file, I got an error saying I couldn't write a list to a text file. I can't simply replace a word for another word, because I have an 'else' clause that covers any word that doesn't match the others I need to replace.
Here's an example of the text I'm trying to modify, this text is contained in a .txt file:
id int,
organization_id int,
billing_month date,
fee_type varchar(100),
rate float,
price float,
uom varchar(25),
amount float,
currency_code_id float,
process_ts timestamptz NOT NULL DEFAULT (now())::timestamptz(6)
I'd like to change:
'int' --> 'BIGINT'
'numeric' --> 'DOUBLE'
'float' --> 'DOUBLE'
ELSE other data type --> 'STRING' .
In the original data, notice that some have other characters, such as "varchar(100)" - I'd like to replace those with "STRING" and eliminate the '(100)' piece as well.
And then either overwrite or create a new text file. So the above example output if replaced properly would be:
id BIGINT,
organization_id BIGINT,
billing_month STRING,
fee_type STRING,
rate DOUBLE,
price DOUBLE,
uom STRING,
amount DOUBLE,
currency_code_id DOUBLE,
process_ts STRING
I'm having trouble knowing if I should be creating lists, and then modifying them, and then writing those lists to the text file, or dictionaries, or some other method I'm not thinking of. I'm very much a beginner so apologies if this isn't very clear.