Quote:
Originally Posted by
looney
Hi Scrutinizer,
How
print x is printing a new line , and when i keep blank like below
HTML Code:
awk '/^#/{print x}1' file
it prints comment line twice. Please explain.
Hello looney,
So when you do
print xit will print actually a NULL value(which is in other words will be a new line only because there is NO value for vriable named x here). But when we do
print, it will definetly print line starting with
# 2 times because you have given command
print without mentioning any line eg-->
$0or any variable like
print x so by default it will print the current line(which offcourse is the line which is starting from
#), then it will print it again because we have mentioned
1 there.
So
awkworks on method of
condition{action} and by writing
1here we are making the condition part as TRUE so action should occure here but we haven't mentioned any action to be done so by default action which is print will print the current line(which is again line starting with
#), so that is why
print xprints a new line(value of variable x which is NULL and then line's value which starts with
#) and
print} 1part prints line 2 times because both of the times we are giving instructions to
awkto print the line starting with
# as explained above.
Thanks,
R. Singh