Field Separator not working 
Author Message
 Field Separator not working

Hello everyone,

    I am having some problems getting Field and Record separators to work
properly.  On the command line I am using a shell script to give me output
of about 100 different nslookups.  I take that and pipe it into sed.  I put
the output of that in a file just so I could work with it faster.  A peice
of the file looks like this:

                                                   Address:      127.0.0.1
                                                   Name:          worldd.com
                                                   Address:
206.54.248.209  #There is no space between the 1st three and the 2nd three!
                                                   A                  ...
... ... ...
                                                   N                 .com
                                                   A                  ...
... ... ...
by default the FS is split in collumns, with Address Name Address
Name....... as $1,   $2 is a : ,   $3 is IP .com IP.....     It also sees
the whole file as a record.  I tried a lot of things in the BEGIN statement
for FS and RS to try to get a record separator every three lines and to get
a field separator on both a new line and a : .  This way I should be able to
print $4 and $6 to get the correct Name and IP.  Is it possible to do what I
am trying to do?

Andrew Eaton



Sun, 17 Nov 2002 03:00:00 GMT  
 Field Separator not working
The print was messed up when I put this in.
                                              The file looks like this
 Address:      127.0.0.1
 Name:          worldd.com
 Address:       206.54.248.209
 A                  ... ... ... ...
 N                 .com
 A                 ... ... ... ...         etc etc no spacing sorry about
this!


Quote:
> Hello everyone,

>     I am having some problems getting Field and Record separators to work
> properly.  On the command line I am using a shell script to give me output
> of about 100 different nslookups.  I take that and pipe it into sed.  I
put
> the output of that in a file just so I could work with it faster.  A peice
> of the file looks like this:

>                                                    Address:      127.0.0.1
>                                                    Name:
worldd.com
>                                                    Address:
> 206.54.248.209  #There is no space between the 1st three and the 2nd
three!
>                                                    A                  ...
> ... ... ...
>                                                    N                 .com
>                                                    A                  ...
> ... ... ...
> by default the FS is split in collumns, with Address Name Address
> Name....... as $1,   $2 is a : ,   $3 is IP .com IP.....     It also sees
> the whole file as a record.  I tried a lot of things in the BEGIN
statement
> for FS and RS to try to get a record separator every three lines and to
get
> a field separator on both a new line and a : .  This way I should be able
to
> print $4 and $6 to get the correct Name and IP.  Is it possible to do what
I
> am trying to do?

> Andrew Eaton



Sun, 17 Nov 2002 03:00:00 GMT  
 Field Separator not working

Quote:

>The print was messed up when I put this in.
>                                              The file looks like this
> Address:      127.0.0.1
> Name:          worldd.com
> Address:       206.54.248.209
> A                  ... ... ... ...
> N                 .com
> A                 ... ... ... ...         etc etc no spacing sorry about
>this!



>> Hello everyone,

>>     I am having some problems getting Field and Record separators to work
>> properly.  On the command line I am using a shell script to give me output
>> of about 100 different nslookups.  I take that and pipe it into sed.  I
>put
>> the output of that in a file just so I could work with it faster.  A peice
>> of the file looks like this:

>>                                                    Address:      127.0.0.1
>>                                                    Name:
>worldd.com
>>                                                    Address:
>> 206.54.248.209  #There is no space between the 1st three and the 2nd
>three!
>>                                                    A                  ...
>> ... ... ...
>>                                                    N                 .com
>>                                                    A                  ...
>> ... ... ...
>> by default the FS is split in collumns, with Address Name Address
>> Name....... as $1,   $2 is a : ,   $3 is IP .com IP.....     It also sees
>> the whole file as a record.  I tried a lot of things in the BEGIN
>statement
>> for FS and RS to try to get a record separator every three lines and to
>get
>> a field separator on both a new line and a : .  This way I should be able
>to
>> print $4 and $6 to get the correct Name and IP.  Is it possible to do what
>I

I suggest that you just do this:

awk '/^Name:/ {name = $2;getline; ip = $2; print name, ip}' infile

This looks for a line starting with "Name:" and saves $2 on that line
as name, and then reads the next line, and saves $2 of it as ip,
then it prints name and ip.

Seems to be what you want to do, without messing with the FS and RS.

Chuck Demas
Needham, Ma.

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

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



Mon, 18 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Multiple field separators for paranthesis not working

2. Dealing with commas as a field separator AND possibly within a field

3. Input field does not seem to work in foreign versions of Windows

4. Populate dictionary fields button does not work

5. Hexadecimal Field Separator

6. multiple field separators in AWK

7. Field Separator

8. Field Separator larger than one character

9. Quoted field separators

10. backslash as field separator

11. field separator

12. Problem with Field Separators

 

 
Powered by phpBB® Forum Software