awk print expression

Hi All,

I have a doubt in awk print exp.

Where in some awk commands have seen a digit 1 appended at the end of the awk ,didnt remember the command .

like ..

cat file |awk '{print }1' 

Could some one help in understanding these cases where we use them.

Regards,
Ganesh,

First:
No need to cat the file to awk
correct awk '{print }1' file
This will print every line two times.

awk has this format
test {action}
this can be repeated
test {action} test {action} test {action}

It this example awk '{print }1' it starts with an action {print } . Since there are no test , it will be true and line will be printed
Next there is an 1 test without action . The default action is print so this will also print the line.

{print} gives same result as 1
So awk '{print }1' could be written awk '{print;print }' or awk '{print }{print}'

1 Like

Thanku Jotne,