Too dificult for me 
Author Message
 Too dificult for me

Hi,
Ive got a problem that I cant solve. Here it is:
Having this line    (value1, value2, value3, ... valueN)
I want to create this text: STORE value1 to TMP(1)
                                      STORE value2 to TMP(2)....
                                      ...
                                      STORE valueN to TMP(N)
Another hints are:
I dont know if betwen the parenthesis and value1 is any blank spaces.
I dont know if betwen valueN and the parenthesis is any blank spaces.

Ill be very glad to any help
Thx,
Ibai



Fri, 09 Jan 2004 16:29:42 GMT  
 Too dificult for me
The following seems to work:
awk '
{
  sub(/^[ \t]*\(/,"",$0);
  sub(/\)[\t]*$/,"",$0);
  split($0,foo,",");
  for (value in foo) {
    sub(/^[\t]*/,"",foo[value]);
    sub(/[ \t]*$/,"",foo[value]);
    printf ("STORE %s to TMP(%u)\n",foo[value],value)
  }
Quote:
}

'

--
BBP



Fri, 09 Jan 2004 17:14:42 GMT  
 Too dificult for me
Thanks for the answer Brieuc,
Ive got more questions about it.

What are first two lines for?

Quote:
>   sub(/^[ \t]*\(/,"",$0);
>   sub(/\)[\t]*$/,"",$0);

Does it work with this entry?
INSERT INTO table VALUES (value1,...valueN)
I think no becouse it is used ^ character for match in the beggining.

Thanks again,
Ibai



Fri, 09 Jan 2004 18:00:06 GMT  
 Too dificult for me

Quote:
> Ive got more questions about it.

> What are first two lines for?

To remove whitespace and tabs before the opening parenthesis and after
the closing parenthesis. I have forgotten the spaces in the second line,

Quote:
> >   sub(/\)[\t]*$/,"",$0);

should be replaced by sub(/\)[ \t]*$/,"",$0);

Quote:
> Does it work with this entry?
> INSERT INTO table VALUES (value1,...valueN)

No. For this entries like this one, you should replace these two lines
by :

  sub(/^[^(]*\(/,"",$0);
  sub (/\)[^)]*$/,"",$0);

--
BBP



Fri, 09 Jan 2004 18:22:32 GMT  
 Too dificult for me
Hi,

Quote:

> Ive got more questions about it.

> What are first two lines for?
> >   sub(/^[ \t]*\(/,"",$0);
> >   sub(/\)[\t]*$/,"",$0);

yes, you've got it, it's for deleting things before and after
the parentheses.

Quote:
> Does it work with this entry?
> INSERT INTO table VALUES (value1,...valueN)
> I think no because it is used ^ character for match in the beggining.

You haven't mentioned this in your first mail.
*If* you input files contains commands shown above,
each one on a separate line, whole one on one line, with no
blank lines, you can get out just by modifying the first of
these two lines to this:
    sub(/^[^(]*\(/,"",$0);
ie. delete all non-( characters before the first occurence of (.

HTH,
        Stepan Kasal



Fri, 09 Jan 2004 18:36:14 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Is "output to printer" (Printing) that dificult ?

 

 
Powered by phpBB® Forum Software