For Programmers: Free Programming Magazines  


Home > Archive > AWK > January 2005 > Re: grabbing data from columns









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: grabbing data from columns
rudz

2005-01-18, 3:57 pm

thanks to the both of you for your replies, the actual report is a lot more
complex than i've made it out to be, the actual report in total can be
found here http://forums.devshed.com/attachmen...tachmentid=6758

i think its a lot more complex than $2, please help, thanks so muchly,
regards

Jürgen Kahrs

2005-01-18, 3:57 pm

rudz wrote:
> thanks to the both of you for your replies, the actual report is a lot more
> complex than i've made it out to be, the actual report in total can be
> found here http://forums.devshed.com/attachmen...tachmentid=6758


This one seemed to work:

awk '($1+1)!=1 && NF>2{print substr($0,60,30)}' report.txt

(6,825.51) 1.000 AUD
8,363.79 1.000 CAD
(138.52) 1.000 CAD
45,454.08 1.000 GBP
68,533.42 1.000 GBP
(12,675.93) 1.000 GBP
(34,570.71) 1.000 GBP
(45,381.67) 1.000 JPY
397.62 1.000 JPY
238,099.67 1.000 JPY
(3,076.40) 1.000 JPY
297,446.56 1.000 USD
(27,860.68) 1.000 USD
41,853.98 1.000 USD
25,386.36 N/A USD
rudz

2005-01-19, 4:07 pm

thanks for you efforts, will i had trouble executing ur script, gave me an
error, Juergen the columns in ur reply, was that the actual output of the
script ? i only get the third row as o/p but you seem to be getting all
the rows, could you please tell me how you managed that ? many thanks
again, cheers

rudz

2005-01-19, 4:07 pm

thanks for you efforts, will i had trouble executing ur script, gave me an
error, Juergen the columns in ur reply, was that the actual output of the
script ? i only get the third row as o/p but you seem to be getting all
the rows, could you please tell me how you managed that ? many thanks
again, cheers

Jürgen Kahrs

2005-01-19, 4:07 pm

Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net EM7B4GRqs6O0kleo/lFa1gBtGwIjXADq1Ce+NYV45zL1+VgR0=
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040927
X-Accept-Language: en-us, en
In-Reply-To: < 7aec5ced03bd4d43cfb84c58765ea2ff@localho
st.talkaboutprogramming.com>
Xref: newsfeed-west.nntpserver.com comp.lang.awk:24449

rudz wrote:

> thanks for you efforts, will i had trouble executing ur script, gave me an
> error, Juergen the columns in ur reply, was that the actual output of the
> script ?


Yes, it was.
In my posting the line break were missing,
so the posting was not properly arranged
column-wise.

> i only get the third row as o/p but you seem to be getting all
> the rows, could you please tell me how you managed that ?


awk '($1+1)!=1 && NF>2{print substr($0,60,30)}' report.txt

Yes, I saw all the rows, each with three columns.
I have no explanation for your problem, except these
guesses:
1. Your data may be different from what you posted.
2. You made a typo while copying the script above.
rudz

2005-01-19, 4:07 pm

negative juergen, seems crazy, downloaded the report from the link that
i've posted, copy pasted the script so there could'nt have been a chance
of a typo and all i got as output was
(138.52) 1.000 CAD, thanks for your help tho :) you have a nice day,
cheers

Jürgen Kahrs

2005-01-19, 4:07 pm

rudz wrote:

> negative juergen, seems crazy, downloaded the report from the link that
> i've posted, copy pasted the script so there could'nt have been a chance
> of a typo and all i got as output was
> (138.52) 1.000 CAD, thanks for your help tho :) you have a nice day,
> cheers


Then it must have to do with line breaks in the
original data file. I guess you tried the script
on a Windows platform and the data file was a
Unix file (\n as line break and not \n\r). I am
not a Windows expert, but maybe it works like
this: awk -F\n ....

Can any MS user help ?
Ed Morton

2005-01-19, 4:07 pm



Jürgen Kahrs wrote:
> rudz wrote:
>
>
>
> Then it must have to do with line breaks in the
> original data file.


It's loaded with control-Ms. Try running dos2unix on it.

Ed.

I guess you tried the script
> on a Windows platform and the data file was a
> Unix file (\n as line break and not \n\r). I am
> not a Windows expert, but maybe it works like
> this: awk -F\n ....
>
> Can any MS user help ?

rudz

2005-01-20, 3:55 am

did run dos2unix on it, din't work :(, ooh maan what am i doing wrong ??

Jürgen Kahrs

2005-01-20, 8:55 am

rudz wrote:

> did run dos2unix on it, din't work :(, ooh maan what am i doing wrong ??


A hexdump of your original file looks like this:

00000210 20 20 20 20 20 44 41 54 45 20 4f 46 20 41 50 50 | DATE OF APP|
00000220 52 41 49 53 41 4c 3a 20 31 32 2f 31 39 2f 32 30 |RAISAL: 12/19/20|
00000230 30 34 0d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 |04...

Usually, on a Micrsoft OS, you have pairs of 0D/0A,
meaning carriage-return/line-feed. Your file looks
broken because there are single 0D characters before
each line break. Who made this file ? Ask him to
produce proper files.

If you install Cygwin on your Windows system, it
would be much easier to handle this problem.
I can only repeat that the following scripts works
for me (tested on my Linux system):

awk '($1+1)!=1 && NF>2{print substr($0,60,30)}' report.txt
Ed Morton

2005-01-20, 3:56 pm



Jürgen Kahrs wrote:
> rudz wrote:
>
>
>
> A hexdump of your original file looks like this:
>
> 00000210 20 20 20 20 20 44 41 54 45 20 4f 46 20 41 50 50 | DATE
> OF APP|
> 00000220 52 41 49 53 41 4c 3a 20 31 32 2f 31 39 2f 32 30 |RAISAL:
> 12/19/20|
> 00000230 30 34 0d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 |04...
> Usually, on a Micrsoft OS, you have pairs of 0D/0A,
> meaning carriage-return/line-feed. Your file looks
> broken because there are single 0D characters before
> each line break. Who made this file ? Ask him to
> produce proper files.
>
> If you install Cygwin on your Windows system, it
> would be much easier to handle this problem.
> I can only repeat that the following scripts works
> for me (tested on my Linux system):
>
> awk '($1+1)!=1 && NF>2{print substr($0,60,30)}' report.txt


Here's what I get running gawk under cygwin:

$ awk '($1+1)!=1 && NF>2{print substr($0,60,30)}' report.txt
(6,825.51) 1.000 AUD
8,363.79 1.000 CAD
(138.52) 1.000 CAD
45,454.08 1.000 GBP
68,533.42 1.000 GBP
(12,675.93) 1.000 GBP
(34,570.71) 1.000 GBP
(45,381.67) 1.000 JPY
397.62 1.000 JPY
238,099.67 1.000 JPY
(3,076.40) 1.000 JPY
297,446.56 1.000 USD
(27,860.68) 1.000 USD
41,853.98 1.000 USD
25,386.36 N/A USD

Regards,

Ed
Jürgen Kahrs

2005-01-20, 3:56 pm

rudz wrote:
> thanks to the both of you for your replies, the actual report is a lot more
> complex than i've made it out to be, the actual report in total can be
> found here http://forums.devshed.com/attachmen...tachmentid=6758


This one seemed to work:

awk '($1+1)!=1 && NF>2{print substr($0,60,30)}' report.txt

(6,825.51) 1.000 AUD
8,363.79 1.000 CAD
(138.52) 1.000 CAD
45,454.08 1.000 GBP
68,533.42 1.000 GBP
(12,675.93) 1.000 GBP
(34,570.71) 1.000 GBP
(45,381.67) 1.000 JPY
397.62 1.000 JPY
238,099.67 1.000 JPY
(3,076.40) 1.000 JPY
297,446.56 1.000 USD
(27,860.68) 1.000 USD
41,853.98 1.000 USD
25,386.36 N/A USD
Ed Morton

2005-01-20, 8:56 pm



Jürgen Kahrs wrote:
> rudz wrote:
>
>
>
> Then it must have to do with line breaks in the
> original data file.


It's loaded with control-Ms. Try running dos2unix on it.

Ed.

I guess you tried the script
> on a Windows platform and the data file was a
> Unix file (\n as line break and not \n\r). I am
> not a Windows expert, but maybe it works like
> this: awk -F\n ....
>
> Can any MS user help ?

Juhan Leemet

2005-01-21, 8:55 pm

On Thu, 20 Jan 2005 13:14:23 +0100, Jürgen Kahrs wrote:
[snippage]
> If you install Cygwin on your Windows system, it
> would be much easier to handle this problem.
> I can only repeat that the following scripts works
> for me (tested on my Linux system):
>
> awk '($1+1)!=1 && NF>2{print substr($0,60,30)}' report.txt


If the OP prefers to stay in a mostly Windows environment, and has money
to spend, I recall that MKS had unix toolkits for MS-DOS, OS/2, Windows
(flavour?) years ago. I don't know if they are still providing it. I don't
know what version of Windows the OP has (and I really don't want to know).
Just a suggestion. Gives you someone to yell at when things don't work.

Now that I think of it, I don't exactly remember if awk was part of the
general toolkit of broken out? I know yacc/lex was a separate package. I
think awk was part of the general unix toolkit (for other/crippled O/Ses).

--
Juhan Leemet
Logicognosis, Inc.

rudz

2005-01-23, 8:55 am

negative juergen, seems crazy, downloaded the report from the link that
i've posted, copy pasted the script so there could'nt have been a chance
of a typo and all i got as output was
(138.52) 1.000 CAD, thanks for your help tho :) you have a nice day,
cheers

Jürgen Kahrs

2005-01-23, 8:55 am

rudz wrote:

> negative juergen, seems crazy, downloaded the report from the link that
> i've posted, copy pasted the script so there could'nt have been a chance
> of a typo and all i got as output was
> (138.52) 1.000 CAD, thanks for your help tho :) you have a nice day,
> cheers


Then it must have to do with line breaks in the
original data file. I guess you tried the script
on a Windows platform and the data file was a
Unix file (\n as line break and not \n\r). I am
not a Windows expert, but maybe it works like
this: awk -F\n ....

Can any MS user help ?
rudz

2005-01-26, 3:55 am

thanks for you efforts, will i had trouble executing ur script, gave me an
error, Juergen the columns in ur reply, was that the actual output of the
script ? i only get the third row as o/p but you seem to be getting all
the rows, could you please tell me how you managed that ? many thanks
again, cheers

Jürgen Kahrs

2005-01-26, 8:55 am

Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net EM7B4GRqs6O0kleo/lFa1gBtGwIjXADq1Ce+NYV45zL1+VgR0=
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040927
X-Accept-Language: en-us, en
In-Reply-To: < 7aec5ced03bd4d43cfb84c58765ea2ff@localho
st.talkaboutprogramming.com>
Xref: newsfeed-west.nntpserver.com comp.lang.awk:24508

rudz wrote:

> thanks for you efforts, will i had trouble executing ur script, gave me an
> error, Juergen the columns in ur reply, was that the actual output of the
> script ?


Yes, it was.
In my posting the line break were missing,
so the posting was not properly arranged
column-wise.

> i only get the third row as o/p but you seem to be getting all
> the rows, could you please tell me how you managed that ?


awk '($1+1)!=1 && NF>2{print substr($0,60,30)}' report.txt

Yes, I saw all the rows, each with three columns.
I have no explanation for your problem, except these
guesses:
1. Your data may be different from what you posted.
2. You made a typo while copying the script above.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com