awk (not the most obvious of command names, *nix commands are usually shortened to under 8 characters or are acronyms/acrostics describing their function, awk is 'just' the initials of the original authors) is fairly simple in it's basic operation, so let's deconstruct what we are doing:
Code:
awk 'BEGIN {OFS="\t"} {print $1,$2,$3,$4}'
awk has three main 'areas' BEGIN, the 'main code' and END. BEGIN code runs once, at the start of the program, END runs once at termination of program and the main code runs once per line of input. Code is grouped together inside { }.
With tha in mind what we do is, at program start we execute the BEGIN section as we have specified one (we don't need to, but in this case it is handy) and in that all we do is {OFS="\t"} which sets an awk internal variable (OFS - Output Field Separator) to the \t (tab) character. What that will do is separate any output files with the tab character instead of the default which is a space.
Then for each line read we output $1, $2, $3, $4, using the print command, as output fields. As we have already set the OFS to be the tab character that means they get printed with tabs.
We don't need any final processing so we don't use the END option.
We could, should you wish, print the headings in the BEGIN function as well:
Code:
BEGIN {OFS="\t"; print "User","TTY","Date","","Time"}
Note the 'dummy' blank output to 'force' the extra tab to make the lining up correct. The semi-colon is the command separator, allowing multi-command lines.