You are not logged in.
Pages: 1
Offline
Use sed.
Offline
Offline
Thank you
I solved all the problems except for a thing.
I'm trying to use the PHP fgetcsv function. The new input csv has ; for delimiter character and \ for escape character.
When I call the function with
fgetcsv($inputFile, 0, ';', '"', '\\')
the script divides this line
978881159779;AL MERCATO CON JOANNE HARRIS. NUOVE RICETTE DALLA CUCINA DI ÇCHOCOLATÈ;F;GARZANTI LIBRI;;EDIZIONI SPECIALI;0;29,5;HARRIS JOANNE\; WARDE FRAN;00/00/00;;08/11/2007;;BA;;0;00/00/00;0;0;0;0;;n;9;MESSAGGERIE;;0;0;00/00/00;00/00/00;15/11/2010;00/00/00;0;;00/00/00;00/00/00;0;250;;1;960;200;252;20;0;C;;454690;Trd.GRANDI L.\13Fmt.8\13Ill.ILL., RIL.\13Dis.C\13;E;;
into this array
Array
(
[0] => 978881159779
[1] => AL MERCATO CON JOANNE HARRIS. NUOVE RICETTE DALLA CUCINA DI ÇCHOCOLATÈ
[2] => F
[3] => GARZANTI LIBRI
[4] =>
[5] => EDIZIONI SPECIALI
[6] => 0
[7] => 29,5
[8] => HARRIS JOANNE\
[9] => WARDE FRAN
[10] => 00/00/00
[11] =>
[12] => 08/11/2007
[13] =>
[14] => BA
[15] =>
[16] => 0
[17] => 00/00/00
[18] => 0
[19] => 0
[20] => 0
[21] => 0
[22] =>
[23] => n
[24] => 9
[25] => MESSAGGERIE
[26] =>
[27] => 0
[28] => 0
[29] => 00/00/00
[30] => 00/00/00
[31] => 15/11/2010
[32] => 00/00/00
[33] => 0
[34] =>
[35] => 00/00/00
[36] => 00/00/00
[37] => 0
[38] => 250
[39] =>
[40] => 1
[41] => 960
[42] => 200
[43] => 252
[44] => 20
[45] => 0
[46] => C
[47] =>
[48] => 454690
[49] => Trd.GRANDI L.\13Fmt.8\13Ill.ILL., RIL.\13Dis.C\13
[50] => E
[51] =>
[52] =>
)
So it considers the ; in \; as a separator and does not skip it. Is that a PHP bug?
Thank you for the help
Egidio
Last edited by Aegidius (2013-04-13 09:29:34)
Offline
Why can't you use sed? This is exactly the type of task it is for. tr might be an option to.
sed -i 's/\t/;/g' files
tr '\t' ';' < infile > outfile
Last edited by Trilby (2013-04-13 11:07:15)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Trilby thanks for the answer
Actually I just solved that problem. Now I have another problem, posted 2 messages above.
Egidio
Offline
Is it an option to use an in between string? sed -i 's/\\;/%escsemi%/g' files and then change it back later?
Offline
Please do not "bump". It is against our policy
Draw attention by posting more information -- what you have learned, what you have read, what you have tried.
Thanks
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Pages: 1