1833356 Members
3279 Online
110051 Solutions
New Discussion

awk field separator

 
SOLVED
Go to solution
Reinhard Burger
Frequent Advisor

awk field separator

Hi

I have a question about awk . Having a file like this

line 1
line 2
line 3
line 4
line next set of lines
line 7
line 8
line 9
line next set of lines ( and so on approx 7000 lines)

i use line next set of lines as recordseparator .
How do i tell awk that a single line should be one field ?
I was looking in the knowledge base but i did'nt find it there. Maybe i'm searching wrong.
keep it simple
7 REPLIES 7
Leif Halvarsson_2
Honored Contributor

Re: awk field separator

Hi
Try with this in the beginning of your script:
BEGIN { FS = \n }
Leif Halvarsson_2
Honored Contributor

Re: awk field separator

Hi
Prehaps you should change the Record separator to a single character.
BEGIN { FS=\n
RS=# }
Reinhard Burger
Frequent Advisor

Re: awk field separator

Hi Leif
Thats what i already tried
and awk is responding with this :

syntax error The source line is 1.
The error context is
BEGIN { FS = >>> \ <<< n ; counter = 0 }
awk: The statement cannot be correctly parsed.
The source line is 1.
syntax error The source line is 1.

any idea ?


Reinhard
keep it simple
Reinhard Burger
Frequent Advisor

Re: awk field separator

The record separator is no problem.
Maybe my example is a little bit silly.
Real i use the single word "DBNAME" as record separator
keep it simple
Leif Halvarsson_2
Honored Contributor
Solution

Re: awk field separator

Hi
For some tome ago i have done this but I dont remember exact.

Have you tested witth quotes
FS= "\n"
Carlos Fernandez Riera
Honored Contributor

Re: awk field separator


Check this:

awk ' BEGIN { RS="x"}^J{ print NR , $0 }' /tmp/87

__>1 line 1
line 2
line 3
line 4
line ne
__>2 t set of lines
line 7
line 8
line 9
line ne
__>3 t set of lines


RS is restricted to one char.
unsupported
Reinhard Burger
Frequent Advisor

Re: awk field separator

Great Leif

You got it !!!


Thanks for your help.
keep it simple