Re: Finding common lines between text files



Logan Shaw wrote:
spibou@xxxxxxxxx wrote:
For understandable code it would then make more sense to
write {print $0}. If someone knows that print without an argument
implies print $0 , then the chances are that they will also know that
an empty rule implies print $0.

I've been using Unix for over 15 years and had no idea that an empty
action was even allowed.

You may have used Unix for 15 years, but you have not studied awk
for 15 minutes. Aside from function definitions, an awk program
consists of pairs like this:

<boolean expression> { <actions> }

If the boolean expression is omitted, the default is naturally 1
(TRUE). (It couldn't default to 0, now could it?)

# print the 2nd field of every record
{ print $2 }

If the actions are omitted, the default is naturally { print $0 }.
(What else would it be?)

# print every record that contains "foo bar"
/foo bar/

I did, however, know that "{ print }" prints
the whole line; that seems obvious enough once you've seen it. (What
else would it do?)

Emit a newline, obviously. That's the way "puts" works in Ruby:

# print "foo" followed by a linefeed
puts 'foo'
# print a linefeed
puts

In newLISP:

# print "foo" followed by a linefeed
(println "foo")
# print a linefeed
(println)

But to do the same in awk you have to print an empty string:

print ""


- Logan

.



Relevant Pages

  • Re: Re: Ruby/Tk: How to access surrounding class from Tk Callback?
    ... # Do something with @root and @foo ... puts @root.foo # DOES NOT WORK ... @root in your button's command is an instance variable ...
    (comp.lang.ruby)
  • Re: A future of awk.
    ... of course expect that new language features would be largely ... compatible and in the "siprit" of awk. ... My programs are sufficiently littered with foo = foo bar ... C/C++ have goto for this purpose. ...
    (comp.lang.awk)
  • Re: matching column variables from two awks!
    ... by sorting and grepping and using awk to print it out. ... foo 20gb 70% ... i'd like to add a new column "accounts" to this print out. ... column from the myFile command, to the appropriate row of the ...
    (comp.lang.awk)
  • Re: A future of awk.
    ... of course expect that new language features would be largely ... compatible and in the "siprit" of awk. ... My programs are sufficiently littered with foo = foo bar ... C/C++ have goto for this purpose. ...
    (comp.lang.awk)
  • Re: FileUtils.chdir thread safety
    ... On Sep 9, 2008, at 1:46 PM, Joel VanderWerf wrote: ... Thread.chdir{puts `ls`} ... the command will enter foo, run ls, and exit. ... chdir 'foo' ...
    (comp.lang.ruby)