help need on nawk script

Dear experts
I have a big file containing several profiles each flagged with "PROFILE" at the beginning of each one. I am trying to use the following command in cshell to seperate each profile and save each one in seperate file. I wrote a script as following:

nawk -v i=0 '{if($1~/PROFILE/) i=i+1, print $0 }' filename > filename$i

I was expecting that it will create different files like file1, file2, ... for each profile but it is not the case. It may need to introduce variable i somehow to shell environment but how can I manage " i " in nawk command can be recognized in shell environment.
Thanks in advances for your advises.
Reza

nawk '$1 ~ /PROFILE/ {out=FILENAME ++i; print $0 > out}' filename

Thanks a lot for your prompt reply. It works. Just as a question is it possible if you please recommend a good reference in unix scripting that you prefer.

for AWking/SEDing you can look into:

http://www.cs.uu.nl/docs/vakken/st/nawk/nawk_toc.html
http://www.faqs.org/faqs/computer-lang/awk/faq/
http://www-personal.umich.edu/~jlawler/routledge/sedawkperl.html
http://www.cs.uu.nl/~piet/docs/nawk/

http://www.ptug.org/sed/sedfaq.htm
http://main.rtfiber.com.tw/~changyj/sed/

http://cfaj.freeshell.org/shell/

There are others, but these should keep you busy for awhile :wink:

1 Like

could you please tell me how to convert a horizontal line into a vertical line using UNIX.
I have 07:37:37 07:31:29 07:21:18 07:08:55 07:08:30 07:00:34 06:53:40 this in a file
.

Help me in getting it into below format.

07:37:37
07:31:29
07:21:18
07:08:55
07:08:30
07:00:34
06:53:40

tr ' ' '
' <file

That is, convert space (in single quotes) to newline (in single quotes).

Edit: didn't notice you were hijacking somebody else's thread. Please don't do that.