[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GAWK error : replace newline with tab in WinXP ?

From: Rajan
Subject: Re: GAWK error : replace newline with tab in WinXP ?
Date: Wed, 26 Mar 2008 20:50:07 -0400

"Harlan Grove" <> wrote in message">
John Bartley K7AAY <> wrote...
awk 'ORS=%NR%1?",":"\t"' %1.tsv > %1.csv

Aside from the typo (not your fault), NR%1 is an error. NR will only
evaluate to integer values, so NR%1 will ALWAYS evaluate to 0, so the
ternary expression NR%1?",":"\t" would ALWAYS evaluate to "\t".

This line of code, . . .
fails for me while running GNUWIN32 gawk 3.1.0  and I would
appreciate guidance from y'all in finding a fix.

CMD doesn't understand single quotes, and the only versions of gawk
that rebuild Unix shell-like command lines are 16-bit versions
compiled with DJGPP which may cause problems with long filenames.

Also, if you mean the following 1-liner from the linked article,

# concatenate every 5 lines of input, using a comma separator
# between fields
awk 'ORS=%NR%5?",":"\n"' file

then it's got a typo. It should be

awk 'ORS=NR%5?",":"\n"' file

but that still requires Unix shell-like quote processing.

I am trying to take a three line file and turn it into a one-line,
tab-separated file, so I can (later on) concatenate multiple files
into one CSV for import into Excel.

Do you mean you want a file containing


to become


and you're going to be doing this in a CMD batch file? If so, you
should use something like

awk "ORS=NR%3?tab:nl" tab=\t nl=\n %1.tsv > %1.csv

I think % has a special meaning in a batch file. Below should work.
gawk "ORS=NR%%3?tab:nl" tab=\t nl=\n %1.tsv > %1.csv
gawk  "ORS=NR%%3?"""\t""":"""\n"""" %1.tsv > %1.csv
gawk -v t="\t"  -v n="\n" "ORS=NR%%3 ? t: n" %1.tsv > %1.csv

reply via email to

[Prev in Thread] Current Thread [Next in Thread]