Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: GAWK error ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 8 Topic 2201 of 2236
Post > Topic >>

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

by "Rajan" <svrajan@[EMAIL PROTECTED] > Mar 26, 2008 at 08:50 PM

"Harlan Grove" <hrlngrv@[EMAIL PROTECTED]
> wrote in message 
news:649fac5b-0093-46f3-928c-550ae7736268@[EMAIL PROTECTED]
> John Bartley K7AAY <john.bart...@[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

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
or
gawk  "ORS=NR%%3?"""\t""":"""\n"""" %1.tsv > %1.csv
or
gawk -v t="\t"  -v n="\n" "ORS=NR%%3 ? t: n" %1.tsv > %1.csv




 8 Posts in Topic:
GAWK error : replace newline with tab in WinXP ?
John Bartley K7AAY <jo  2008-03-25 08:50:33 
Re: GAWK error : replace newline with tab in WinXP ?
Hermann Peifer <peifer  2008-03-25 10:11:14 
Re: GAWK error : replace newline with tab in WinXP ?
Kam-Hung Soh <kamhung.  2008-03-25 19:11:54 
Re: GAWK error : replace newline with tab in WinXP ?
Kam-Hung Soh <kamhung.  2008-03-25 20:30:38 
Re: GAWK error : replace newline with tab in WinXP ?
John Bartley K7AAY <jo  2008-03-26 09:02:46 
Re: GAWK error : replace newline with tab in WinXP ?
Hermann Peifer <peifer  2008-03-26 19:40:20 
Re: GAWK error : replace newline with tab in WinXP ?
Harlan Grove <hrlngrv@  2008-03-26 13:57:58 
Re: GAWK error : replace newline with tab in WinXP ?
"Rajan" <svr  2008-03-26 20:50:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 0:12:03 CDT 2008.