12345 City Name Example 54321 Other City 24680 Third
I want to 'walk' through a text file and convert every line to look like this
'12345','City Name Example' '54321','Other City' '24680','Third'
How do.... I have like 200 lines in this file
What languages do you know/have available?
well i guess i could upload the file and process it via php
or grep
or regex
Is the structure of the source file consistent, with one numeric string before N alpha strings?
each line consists of five numeric characters (zipcode), a space, and then variable length string sometimes containing spaces (city names)
Since you have PHP, you should be able to:
1. Open file 2. Loop through each line of file 3. Do a split() on the line, giving you an array 4. Declare an empty string, append a single quote, the first element of the array, then a quote, comma, and quote characters 5. Loop through remaining array elements 6. Append each element to the string 7. Append a final quote and CR/LF 8. Write string to output 9. Continue loop through file until EOF
Been a few years since I did PHP, but I've done much similar to this with it. Shouldn't be a problem, you may have to interpret my pseudocode a bit though.