what is awk '{print $1+0.45 “ ” $2 “ ” $3 }' file1> file2?
What does awk '{print $1+0.45 " " $2 " " $3 }' positionXYZ > positionX0.45YZ
mean? Does it mean changing a row in the first file and put the new data into the second one?
awk
add a comment |
What does awk '{print $1+0.45 " " $2 " " $3 }' positionXYZ > positionX0.45YZ
mean? Does it mean changing a row in the first file and put the new data into the second one?
awk
add a comment |
What does awk '{print $1+0.45 " " $2 " " $3 }' positionXYZ > positionX0.45YZ
mean? Does it mean changing a row in the first file and put the new data into the second one?
awk
What does awk '{print $1+0.45 " " $2 " " $3 }' positionXYZ > positionX0.45YZ
mean? Does it mean changing a row in the first file and put the new data into the second one?
awk
awk
edited Jan 29 '14 at 23:58
Gilles
539k12810911606
539k12810911606
asked Jan 29 '14 at 21:49
MevaMeva
1032310
1032310
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.
awk reads each line of file1 and runs the script between {}
The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...
The parameters are printed except $1 is added with 0.45
add a comment |
$1, $2, $3 mean placeholders of value got at the previous operation.
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f111542%2fwhat-is-awk-print-10-45-2-3-file1-file2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
answered Jan 29 '14 at 21:58
terdon♦terdon
131k32258436
131k32258436
add a comment |
add a comment |
file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.
awk reads each line of file1 and runs the script between {}
The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...
The parameters are printed except $1 is added with 0.45
add a comment |
file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.
awk reads each line of file1 and runs the script between {}
The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...
The parameters are printed except $1 is added with 0.45
add a comment |
file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.
awk reads each line of file1 and runs the script between {}
The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...
The parameters are printed except $1 is added with 0.45
file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.
awk reads each line of file1 and runs the script between {}
The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...
The parameters are printed except $1 is added with 0.45
edited Jan 29 '14 at 22:05
answered Jan 29 '14 at 21:58
X TianX Tian
7,72712136
7,72712136
add a comment |
add a comment |
$1, $2, $3 mean placeholders of value got at the previous operation.
New contributor
add a comment |
$1, $2, $3 mean placeholders of value got at the previous operation.
New contributor
add a comment |
$1, $2, $3 mean placeholders of value got at the previous operation.
New contributor
$1, $2, $3 mean placeholders of value got at the previous operation.
New contributor
New contributor
answered 33 mins ago
imissyouimissyou
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f111542%2fwhat-is-awk-print-10-45-2-3-file1-file2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown