|
List Info
Thread: GAWK error : replace newline with tab in WinXP ?
|
|
| GAWK error : replace newline with tab in
WinXP ? |
  United States |
2008-03-25 10:50:33 |
awk 'ORS=%NR%1?",":"t"' %1.tsv >
%1.csv
This line of code, adapted from http
://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.jerryp
ournelle.com/view/
currentview.html) and the physics are using the collected
wisdom of
Fred on Everything (http://www.fredoneve
rything.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.
|
|
| Re: GAWK error : replace newline with
tab in WinXP ? |
  Australia |
2008-03-25 21:11:54 |
On Mar 26, 2:50 am, John Bartley K7AAY <john.bart... gmail.com> 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.jerryp
ournelle.com/view/
> currentview.html) and the physics are using the
collected wisdom of
> Fred on Everything (http://www.fredoneve
rything.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.)
Try:
gawk
"ORS=1?"^"","^"":"^&
quot;"t"^""" %1.tsv > %1.csv
Regards,
--
Kam-Hung Soh <a href="http://k
amhungsoh.com/blog">Software Salariman</
a>
|
|
| Re: GAWK error : replace newline with
tab in WinXP ? |
  United States |
2008-03-26 19:50:07 |
"Harlan Grove" <hrlngrv gmail.com> wrote in
message
news:649fac5b-0093-46f3-928c-550ae7736268 b64g2000hsa.googlegroups.com...
> John Bartley K7AAY <john.bart... gmail.com> 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
|
|
| Re: GAWK error : replace newline with
tab in WinXP ? |
  United States |
2008-03-26 15:57:58 |
John Bartley K7AAY <john.bart... gmail.com> 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
|
|
[1-4]
|
|