Re: How to read files with commas as separators?



<mostly offtopic>
On Tue, 18 Mar 2008 22:32:35 -0800, glen herrmannsfeldt
<gah@xxxxxxxxxxxxxxxx> wrote:

zuying@xxxxxxxxx wrote:

But the data file is of 5Gb in size so it's hard to add another comma
there in every occasion.

awk will do it with

awk '{print $0,","}' oldfile > newfile
(the quote conventions on windows make it harder to do inline)

Don't need the unquoted comma; that generates a field separator (which
defaults to space, harmless here) before the comma. String
concatentation in awk is done with the null operator:
sh$ awk '{print $0 ","}'
You can avoid awk "string" literals for some cases including this one
in Windows command processor by using a variable:
CMD> awk -vco=, "{print $0 co}"

However, sed is usually available where awk is, and has no issue:
sed s/$/,/ oldfile >newfile
(Even in Unixy shells where $name is special, $/ isn't.)

Also pre-patching doubles the disc space and triples the time to
read,write,read all the data, if those are problems. Unless the
Fortran can be changed to read from stdin (typically 5, as we just
discussed) and you pipe the results into it, then you only have the
cost of pipe buffering which is reasonably small. But if you can
change the Fortran, the internal-read already discussed works.

- formerly david.thompson1 || achar(64) || worldnet.att.net
.



Relevant Pages

  • Re: Automatisierte TextVerarbeitung
    ... AWK - oder bessergesagt "awk" kam mir doch gleich irgendwie bekannt vor ... Einige kann man auch als exe fuer Windows beziehen ... Ich habe soeben ein altes mawk herausgekramt und ein mini-awk script, ... Betreff: Re: where are the binaries for GAWK? ...
    (microsoft.public.de.german.windowsxp.sonstiges)
  • Re: alternatives to awk
    ... I need to create scripts in Windows hosted QNX Momentics. ... Why do you need an alternative to the AWK language? ...
    (comp.lang.awk)
  • Re: AWK ? ?
    ... > hey thanks, ... > one more question can run my AWK program on windows? ...
    (comp.unix.questions)
  • Re: awk and sorting file
    ... There's no sort function builtin in standard awk. ... Are you working in a Unix environment? ... This person is working on Windows. ...
    (comp.lang.awk)
  • Re: MicroFocus & Win XP file problems
    ... Actually AWK and sed have many implementations on many systems ... The main point is that with a 1.1 Gb file the 'Windows Way' of loading ... in the file visually is quite inappropriate to the problem, ... For this particular problem the 'Unix Way' of using a script to pass ...
    (comp.lang.cobol)