> > fileName=number ".out"
> > print >fileName
> > next
> > }
> > { print >"aux.out"
> > }' infile
############################################################
I can see the program nicely arranged on my screen.
############################################################
Quote:> It's difficult to read this script because of the strange
> formatting and the misalignment of the statements. Are you
> preparing your Usenet news articles using a proportional font
> and a Japanese character encoding? If so, please realize that
> most Usenet news readers are NOT using your same font, font
> size, screen resolution, character encoding, etc.
############################################################
I indeed use Japanese encoding. However, I find your comments
unecessary.
############################################################
> Here is the same script formatted more conventionally:
> number = substr($0, 2, 1)
> fileName = number ".out"
> print >fileName
> next
> }
> {
> print >"aux.out"
> }
> This is much easier to read and understand.
############################################################
Thanks: now it looks perfect. The perfect solution out of synergy.
############################################################
> The regular expression you use here suffers the same problem
> as those in your sed script: it will have the effect of putting
> file; namely, the file "1.out". You're proffering a solution
> based on assumptions without stating those assumptions, which
> can be misleading.
############################################################
I assume that the user is intelligent: after having read the solution and
understood it, he/she should be able to alter the patterns, or
the program as a whole.
############################################################
> Personally, I would have found your awk solution easier to
> understand if it were expressed more succinctly, like this:
> {
> print >substr($0, 2, 1) ".out"
> else
> print >"aux.out"
> }
############################################################
awk was made to put cases into patterns left and to avoid to write ifs.
I strongly object against advocating
the "empty pattern" { if-then-else } style.
Your proposal is C-style. not awk-style.
Furthermore, I find it extremly useful to set
variables with meaningful names: such as
outputfile=substr($0, 2, 1) ".out" even if used
only once.
This has two advantages:
a)
The program is understandable for me a year from now.
b)
Some awk's do not handle >-concatenation properly.
############################################################
> Or even like this:
> Admittedly, programmers who aren't accustomed to the conditional
> statement of C, Perl, and awk will perhaps find this version TOO
> succint. But expressing the program in this way serves to emphasize
> that, indeed, the problem is easily reduced to a single print
> statement, where the only variable is the name of the file to which
> output from that print statement is redirected. My versions also
> eliminate unnecessary assignments to variables ("number" and
> "fileName" in your version) and the dubious use of a next statement
> where a more stuctured control construct is appropriate.
############################################################
As commented above (and in famous C-books): variables can serve
the purpose of readability/maintainability/correctness. However your
solution is short and sweet.
############################################################
END
############################################################
############################################################
############################################################
############################################################
############################################################
############################################################
############################################################
############################################################
############################################################
############################################################
############################################################
############################################################
############################################################