'split' creates extra output 
Author Message
 'split' creates extra output

Hey you all,

I'm trying to use 'awk' in order to change my data-file to something
SPSS is willing to read errorless.

In order to do that, I'm regarding my whole (multi-line) input-file as
one record (RS=""), and I split the fields using FS=":"

So far so good. However,

Several of my fields contain both a number and a string,
like '1.2252  H1x'

This (of course) should be splitted. I do that by using 'split'
according to:

split($68,Hx1," ")

Actually works exactly the right way but for one thing:
Every call of split causes the awk-programma to generate either the
whole file or the whole record (which is in my case the same) as
output. No so very nice.

the question is:
a) Is this normal behaviour
b) How can I avoid this from happening, while using 'split'?
c) Should I use something else instead?

ThanX a lot for your help in advance

Marlies



Mon, 25 Jul 2005 19:14:00 GMT  
 'split' creates extra output

Quote:

> Hey you all,

> I'm trying to use 'awk' in order to change my data-file to something
> SPSS is willing to read errorless.

> In order to do that, I'm regarding my whole (multi-line) input-file as
> one record (RS=""), and I split the fields using FS=":"

Blank lines separate records -- are you sure there are none?

New lines (as well as colons) separate fields -- are you sure
all your linebreaks are in appropriate places?

Quote:

> So far so good. However,

> Several of my fields contain both a number and a string,
> like '1.2252  H1x'

> This (of course) should be splitted. I do that by using 'split'
> according to:

> split($68,Hx1," ")

> Actually works exactly the right way but for one thing:
> Every call of split causes the awk-programma to generate either the
> whole file or the whole record (which is in my case the same) as
> output. No so very nice.

split should not generate any output. Are you talking about an error
message? Or do you do some later processing? Do you check
the return value of split?

It would be easier to help if you post a sample of your data file,
together with an example of what you and SPSS want it to look like.
And, of course, your awk program.

Then we can assess your awk, or see if there is an easier way to
do this task.

John.



Mon, 25 Jul 2005 19:52:57 GMT  
 'split' creates extra output

Quote:

> split($68,Hx1," ")

> Actually works exactly the right way but for one thing:
> Every call of split causes the awk-programma to generate either the
> whole file or the whole record (which is in my case the same) as
> output. No so very nice.

> the question is:
> a) Is this normal behaviour
> b) How can I avoid this from happening, while using 'split'?
> c) Should I use something else instead?

> ThanX a lot for your help in advance

  If split(...) generates the entire record, then you probably don't
have it inside braces. In other words,

   awk -F: 'split($68,Hx1," ")'

will print the record if the array Hx1 could be created. But if the
split() function is inside of braces, then the record will not be
printed unless you explicitly tell it to. While I suppose that your
awk script is probably within some type of script, check to see if
you have inadvertently mismatched the brace levels, and whether the
split(...) function is now being treated as a "pattern" instead of
being treated as an "action".



Mon, 25 Jul 2005 23:33:42 GMT  
 'split' creates extra output

Quote:


> > split($68,Hx1," ")

> > Actually works exactly the right way but for one thing:
> > Every call of split causes the awk-programma to generate either the
> > whole file or the whole record (which is in my case the same) as
> > output. No so very nice.

> > the question is:
> > a) Is this normal behaviour
> > b) How can I avoid this from happening, while using 'split'?
> > c) Should I use something else instead?

> > ThanX a lot for your help in advance

>   If split(...) generates the entire record, then you probably don't
> have it inside braces. In other words,

>    awk -F: 'split($68,Hx1," ")'

> will print the record if the array Hx1 could be created. But if the
> split() function is inside of braces, then the record will not be
> printed unless you explicitly tell it to. While I suppose that your
> awk script is probably within some type of script, check to see if
> you have inadvertently mismatched the brace levels, and whether the
> split(...) function is now being treated as a "pattern" instead of
> being treated as an "action".

ThanX Eric,
This is exactly what went wrong.

I found this out accidentally when I was trying to do everything a
different way (though still had to use 'split') and suddenly only the
desired output was generated. (This doesn't mean that I knew why it
went right this time...)

So no accidental mismatching occured here, I just found out (say about
a few minutes ago) that the braces in 'awk' have some more function
than I thought.
I'm afraid I know just enough about 'awk' to put the right commands in
te right order, and be glad  that everything turns out all right.
However your remark regardign 'patterns' and 'actions' has just made
me find chapter eight, which looks exactly like I should read it
urgently.

Thanks a lot,
Now I can feed SPSS

Marlies



Tue, 26 Jul 2005 22:05:51 GMT  
 'split' creates extra output

Quote:


> > Hey you all,

> > I'm trying to use 'awk' in order to change my data-file to something
> > SPSS is willing to read errorless.

> > In order to do that, I'm regarding my whole (multi-line) input-file as
> > one record (RS=""), and I split the fields using FS=":"

> Blank lines separate records -- are you sure there are none?

> New lines (as well as colons) separate fields -- are you sure
> all your linebreaks are in appropriate places?

> > So far so good. However,

> > Several of my fields contain both a number and a string,
> > like '1.2252  H1x'

> > This (of course) should be splitted. I do that by using 'split'
> > according to:

> > split($68,Hx1," ")

> > Actually works exactly the right way but for one thing:
> > Every call of split causes the awk-programma to generate either the
> > whole file or the whole record (which is in my case the same) as
> > output. No so very nice.

> split should not generate any output. Are you talking about an error
> message? Or do you do some later processing? Do you check
> the return value of split?

> It would be easier to help if you post a sample of your data file,
> together with an example of what you and SPSS want it to look like.
> And, of course, your awk program.

> Then we can assess your awk, or see if there is an easier way to
> do this task.

> John.

Hi John,

Thanks for the efford to read about my problem.
The reason why I tried to describe my problem (instead of showing my
three lines of code) was because I didn't think there was something
wrong with my code (woehahahahaa, a bit naieve I admit), but basically
wondered whether 'split' generating output was normal behaviour.
Especially since my only problem was some unwanted extra output. In
basis the programme did as I intended.

However, as you can see, Eric has assumed (correctly) that I made a
really basic error in my script concerning braces. So no need to
plunge my records on the net after all (*phiew*).

ThanX for the trouble,

Marlies



Tue, 26 Jul 2005 22:15:26 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Splitting 'and' conditions into multiple conditions

2. splitting using '\' as a delimiter

3. Behavior of 'split' command

4. newbie: emacs 'split-string'

5. Splitting a string every 'n'

6. delimiter '::' with split

7. Outputting 'Raw' printer data

8. Undetermined Output in 'X' state

9. Redefining 'Class'Output

10. capture 'system' output

11. Grab output from 'tail'

12. Help with variable FEQ's in run time CREATE's

 

 
Powered by phpBB® Forum Software