what is awk '{print $1+0.45 " " $2 " " $3 }' file1> file2?
Let's break this down. awk '{foo}' file
will apply the expression foo
to each line of file
and print the result to the terminal (standard output). awk
splits its input lines on white space (by default) and saves each field as $1
, $2
etc.
So, the actual expression you are running means: read each input line, add 0.45 to the value of the first field and then print that field as well as the second and third one. This is most easily explained with a simple example:
$ cat file.txt
10 20 30 40
50 60 70 80
$ awk '{print $1+0.45 " " $2 " " $3 }' file.txt
10.45 20 30
50.45 60 70
So, as you can see, the awk
script added 0.45 to the first field of each line and then printed it along with the second and third. The fourth was ignored since you did not tell it to print $4
.
The next bit has nothing to do with awk
, the >
symbol is for output redirection and is used by the shell (bash or zsh or whatever you are using). In general command > file
will save the output of command
in the file file
overwriting the contents of the file if it exists and creating it if it does not.
Putting everything together:
$ ls
file.txt
$ cat file.txt
10 20 30 40
50 60 70 80
$ awk '{print $1+0.45 " " $2 " " $3 }' file.txt > file2.txt
$ ls
file2.txt file.txt
$ cat file2.txt
10.45 20 30
50.45 60 70