FS should set separate at blank and dot 
Author Message
 FS should set separate at blank and dot

Hi,

I've tried several ways but I did'nt solve my problem.

How must FS to be set to seperate the records into fields
at the default and at dots.
It should be devided like this if the record is this one:

$0:     #*/    VERT   :      GTI.HOPE.Sol__ution.12.who.knows?     /*

$1:   #*/                    $7:   12
$2:   VERT                   $8:   who
$3:   :                      $9:   knows?
$4:   GTI                   $10:   /*
$5:   HOPE
$6:   Sol__ution

Does anybody know an answer ?
Special thanks.

If it is possible write an answer for both: nawk and gawk
if the impletations behave different in this case.

Thanks,
Ludger



Tue, 05 Feb 2002 03:00:00 GMT  
 FS should set separate at blank and dot
Try this:

$ cat inputfile

  #*/    VERT   :      GTI.HOPE.Sol__ution.12.who.knows?     /*

$ awk '{gsub(/\./, " ")}{print}' inputfile

  #*/    VERT   :      GTI HOPE Sol__ution 12 who knows?     /*

*********************************************************************

Quote:

> Hi,

> I've tried several ways but I did'nt solve my problem.

> How must FS to be set to seperate the records into fields
> at the default and at dots.
> It should be devided like this if the record is this one:

> $0:     #*/    VERT   :      GTI.HOPE.Sol__ution.12.who.knows?     /*

> $1:   #*/                    $7:   12
> $2:   VERT                   $8:   who
> $3:   :                      $9:   knows?
> $4:   GTI                   $10:   /*
> $5:   HOPE
> $6:   Sol__ution

> Does anybody know an answer ?
> Special thanks.

> If it is possible write an answer for both: nawk and gawk
> if the impletations behave different in this case.

> Thanks,
> Ludger



Tue, 05 Feb 2002 03:00:00 GMT  
 FS should set separate at blank and dot

Quote:

> Hi,

> I've tried several ways but I did'nt solve my problem.

> How must FS to be set to seperate the records into fields
> at the default and at dots.
> It should be devided like this if the record is this one:

> $0:     #*/    VERT   :      GTI.HOPE.Sol__ution.12.who.knows?     /*

> $1:   #*/                    $7:   12
> $2:   VERT                   $8:   who
> $3:   :                      $9:   knows?
> $4:   GTI                   $10:   /*
> $5:   HOPE
> $6:   Sol__ution

> Does anybody know an answer ?
> Special thanks.

> If it is possible write an answer for both: nawk and gawk
> if the impletations behave different in this case.

> Thanks,
> Ludger

The field seperator can be set as follows:

BEGIN {
    FS = "([.]|([ \t]+)?"

Quote:
}

This setting can work well under LINUX, so it should be useful for you.

Best regards,
J. S. Lai



Tue, 05 Feb 2002 03:00:00 GMT  
 FS should set separate at blank and dot


Quote:
>Hi,

>I've tried several ways but I did'nt solve my problem.

>How must FS to be set to seperate the records into fields
>at the default and at dots.
>It should be devided like this if the record is this one:

>$0:     #*/    VERT   :      GTI.HOPE.Sol__ution.12.who.knows?     /*

>$1:   #*/                    $7:   12
>$2:   VERT                   $8:   who
>$3:   :                      $9:   knows?
>$4:   GTI                   $10:   /*
>$5:   HOPE
>$6:   Sol__ution

>Does anybody know an answer ?
>Special thanks.

>If it is possible write an answer for both: nawk and gawk
>if the impletations behave different in this case.

>Thanks,
>Ludger

In gawk one could write:

gawk -F"[.]|[ \t]*" '{for(i=0;i<=NF;i++){print "#"i":       ",$i}}' infile

Which produces:

#0:      #*/    VERT   :      GTI.HOPE.Sol__ution.12.who.knows?     /*
#1:      #*/
#2:      VERT
#3:      :
#4:      GTI
#5:      HOPE
#6:      Sol__ution
#7:      12
#8:      who
#9:      knows?
#10:     /*

It seems to work in nawk too.

Some older versions of awk only accept single characters for the
FS as opposed to regular expressions.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 05 Feb 2002 03:00:00 GMT  
 FS should set separate at blank and dot

Quote:

> Hi,

> I've tried several ways but I did'nt solve my problem.

> How must FS to be set to seperate the records into fields
> at the default and at dots.
> It should be devided like this if the record is this one:

> $0:     #*/    VERT   :      GTI.HOPE.Sol__ution.12.who.knows?     /*

> $1:   #*/                    $7:   12
> $2:   VERT                   $8:   who
> $3:   :                      $9:   knows?
> $4:   GTI                   $10:   /*
> $5:   HOPE
> $6:   Sol__ution

> Does anybody know an answer ?
> Special thanks.

> If it is possible write an answer for both: nawk and gawk
> if the impletations behave different in this case.

> Thanks,
> Ludger

This works OK on HP-UX:

$ awk 'BEGIN{FS="\.|[ ]+"} {for(i=0;i<=NF;i++) \

Quote:
> print "$"i, $i}' some.data

$0   #*/    VERT  :  GTI.HOPE.Sol__ution.12.who.knows?   /*
$1
$2 #*/
$3 VERT
$4 :
$5 GTI
$6 HOPE
$7 Sol__ution
$8 12
$9 who
$10 knows?
$11 /*
$

Where some.data contains your test string.

HTH
--


Fax2Email  0870 052 2717
Opinions expressed are my own and not necessarily those of my employer.



Fri, 08 Feb 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. dot-dot-dot

2. setting RS for records separated by white space

3. Setting a variable in 2 separate always blocks

4. Pipelined FP add (Separate Register Sets)

5. How to set BLANK in $gr_waves.

6. Comma dot (1,000.00) to dot comma (1.000,00)

7. Setting FS to " character

8. Loop separate sounds, separate intervals

9. Setting fs in real mode

10. Separate keyword and separate compilation with GNAT?

11. separate keyword and separate compilation with GNAT?

12. FS Micro Focus COBOL Manuals V3.2 Complete Set

 

 
Powered by phpBB® Forum Software