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

Harlan Grove <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization http://groups.google.com
Message-ID <649fac5b-0093-46f3-928c-550ae7736268@b64g2000hsa.googlegroups.com>
John Bartley K7AAY <[email protected]> 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

line1
line2
line3

to become

line1[tab]line2[tab]line3

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.