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 6 of 8 Topic 2201 of 2236
Post > Topic >>

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

by Hermann Peifer <peifer@[EMAIL PROTECTED] > Mar 26, 2008 at 07:40 PM

John Bartley K7AAY wrote:
> On Mar 25, 8:30 pm, Kam-Hung Soh <kamhung....@[EMAIL PROTECTED]
> wrote:
>> On Mar 26, 1:11 pm, Kam-Hung Soh <kamhung....@[EMAIL PROTECTED]
> wrote:
>>
>>
>>
>>> On Mar 26, 2:50 am, John Bartley K7AAY <john.bart...@[EMAIL PROTECTED]
> wrote:
>>>> awk 'ORS=%NR%1?",":"\t"' %1.tsv > %1.csv
>>>> This line of code, adapted
fromhttp://www.ee.ucl.ac.uk/~hamed/misc/awk1line.txt
>>>> fails for me while running GNUWIN32 gawk 3.1.0  and I would
appreciate
>>>> guidance from y'all in finding a fix.
>>>> 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.
>>>> Thank you kindly in advance.
>>>> The TSV files look something like this:
>>>> XY_12345_Acme_Blinder_Coughdrop-Optimal
>>>> 9
>>>> This test will run Lorem ipsum dolor sit amet, consectetuer
adipiscing
>>>> elit. Fusce a diam. Etiam sapien pede, placerat quis, malesuada in,
>>>> eleifend quis, velit. Praesent imperdiet cursus odio. Praesent vel
>>>> lorem. Pellentesque dignissim, felis non euismod rhoncus, felis pede
>>>> condimentum lacus, ac accumsan mi leo sit amet lacus. Donec porta
nunc
>>>> ut sapien. Morbi pede. Nulla tincidunt nisi mollis augue. Praesent
>>>> dapibus cursus tellus. Sed accumsan dui sed metus. Morbi lacus. Nunc
>>>> placerat arcu tincidunt turpis. Proin tristique ullamcorper velit.
>>>> Proin id justo egestas erat interdum volutpat. Sed sodales massa sit
>>>> amet orci. Duis hendrerit volutpat velit. Aenean vel libero.
>>>> Suspendisse potenti.##Test will run the following sequence:#1. Run in
>>>> circles#2. Scream#3. And shout###The following are is a more in-depth
>>>> look at what each of Praesent tincidunt egestas nulla. Nullam non mi.
>>>> Ut tellus ipsum, molestie fringilla, eleifend non, pulvinar vel,
>>>> sapien. Nullam et mi nec neque tempus iaculis. Sed quam. Aenean orci
>>>> nulla, sodales et, pulvinar sodales, sagittis vel, turpis. Aliquam
>>>> massa quam, porttitor vitae, rhoncus ac, volutpat at, sem. Cras sed
>>>> lorem. Mauris faucibus erat non neque. Nunc bibendum mattis mi.
>>>> Quisque elementum diam at lectus.
(http://www.jerrypournelle.com/view/
>>>> currentview.html) and the physics are using the collected wisdom of
>>>> Fred on Everything (http://www.fredoneverything.net/
>>>> FOE_Frame_Column.htm).#The tests are run in Ut arcu. Nulla venenatis
>>>> egestas risus. Vestibulum nec ligula. Aenean adipiscing risus quis
>>>> libero vulputate rutrum. Proin sagittis orci non mi. Mauris magna.
>>>> Aliquam malesuada lectus vitae pede. Integer lacus risus, volutpat
>>>> sed, ultrices in, venenatis et, libero. Praesent euismod mauris id
>>>> turpis hendrerit egestas. Mauris tristique. Aliquam vel enim posuere
>>>> nisi vehicula laoreet. Integer tempus vestibulum odio. Donec et quam.
>>>> Maecenas lacinia nulla sed est. Donec mollis ligula sed tellus.
>>>> Phasellus quis eros a sem vulputate eleifend. Phasellus sagittis
felis
>>>> id tellus. Nunc condimentum ultricies sem. ##Test 1:# How many Aggies
>>>> does it take to screw in a lightbulb? #Sed blandit, tellus non cursus
>>>> blandit, est justo sollicitudin lectus, vel mollis lectus magna ac
>>>> pede. Aliquam aliquam lorem sed erat. Quisque rutrum, enim sit amet
>>>> ornare varius, dui libero lacinia orci, non iaculis mi sapien non
>>>> urna. Sed massa ante, elementum ut, posuere quis, interdum eget,
>>>> ipsum. Duis blandit condimentum elit. Aliquam volutpat iaculis leo.
>>>> Suspendisse nibh nibh, dignissim cursus, elementum sed, convallis eu,
>>>> metus. Phasellus vel magna. Aenean nulla nisi, rhoncus non, egestas
>>>> non, commodo bibendum, pede. Aliquam justo. Aliquam sapien tortor,
>>>> placerat accumsan, auctor porta, rhoncus sed, tortor. Ut tempus.
>>>> Curabitur vitae lectus quis lectus venenatis posuere. Curabitur
>>>> venenatis. Donec elementum eros. Praesent eget ligula nec metus
>>>> molestie hendrerit. Sed at nisi.
>>> When I tried your script on Windows XP using GNU Awk 3.1.3, I found
>>> this error:
>>> gawk: cmd. line:1: 'ORS=1?,:\t'
>>> gawk: cmd. line:1: ^ invalid char ''' in expression
>>> If that is the problem you encountered, you have to escape the double-
>>> quote mark in a double-quoted string using the "^" (double-quote caret
>>> double-quote) sequence.  (It's as awkward as it sounds.)
> <snip>
> 
>> Correction: use three double-quotes to escape a double-quote.
>>
>> gawk "ORS=1?""",""":"""\t"""" %1.tsv > %1.csv
>>
>> --
>> Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software
Salariman</a>
> 
> I appreciate the suggestion, but that led to a new problem, four gawk
> error messages:
> 
> gawk: cmd. line:1: ORS=1?,:\t
> gawk: cmd. line:1:             ^ parse error
> 
>                (The caret lines up with the comma on the first line.)
> 
> 
> gawk: cmd. line:1: ORD=1?,:\t
> gawk: cmd. line:1:              ^ backslash not last character
> 
>                 (The caret lines up with the backstroke on the third
> line)
> 
> I'll take another look at this later today.
> Again, thank you; appreciate the effort.

To avoid quoting problems alltogether, you should place the code into a 
file, say: script.awk and run the command like this:

gawk -f script.awk infile > outfile

And if you really want to change 3 lines into 1 line with tab-delimited 
fields, then this code will do it:

$ cat script.awk
ORS = NR%3 ? "\t" : "\n"
$ cat data
1
2
3
4
5
6
7
8
9
$ awk -f script.awk data
1       2       3
4       5       6
7       8       9




 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 Fri May 16 23:41:35 CDT 2008.