Re: Finding common lines between text files
- From: "William James" <w_a_x_man@xxxxxxxxx>
- Date: 3 Jul 2006 18:41:25 -0700
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
.
- Follow-Ups:
- Re: Finding common lines between text files
- From: Logan Shaw
- Re: Finding common lines between text files
- From: spibou@xxxxxxxxx
- Re: Finding common lines between text files
- References:
- Finding common lines between text files
- From: Henrik Goldman
- Re: Finding common lines between text files
- From: Henrik Goldman
- Re: Finding common lines between text files
- From: Logan Shaw
- Re: Finding common lines between text files
- From: Chris F.A. Johnson
- Re: Finding common lines between text files
- From: spibou@xxxxxxxxx
- Re: Finding common lines between text files
- From: Chris F.A. Johnson
- Re: Finding common lines between text files
- From: spibou@xxxxxxxxx
- Re: Finding common lines between text files
- From: Logan Shaw
- Finding common lines between text files
- Prev by Date: Re: Finding common lines between text files
- Next by Date: Re: dirname return value
- Previous by thread: Re: Finding common lines between text files
- Next by thread: Re: Finding common lines between text files
- Index(es):
Relevant Pages
|