Keep all rows according to common numbers in specific columns
I have a file with 15 columns and I would like to filter the rows that have the same values in common in the columns number: 1,3,5,8,11,14. Basically the columns mass and artificial_mass need to have the same common value. For example from a table like this.
Input
mass Ret_time_min mass Ret_time_min mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
229 1.573 229 1.597 229 1.585 231 229 1.576 231 229 1.59 233 231 12.89
229 1.905 229 2.004 229 2.186 232 230 11.919 235 233 12.91 235 233 12.929
229 2.303 229 2.139 229 2.242 238 236 0.689 238 236 0.684 238 236 0.689
229 2.59 229 2.291 229 2.365 238 236 0.803 238 236 0.796 238 236 0.788
229 2.737 229 2.484 229 5.41 239 237 0.68 239 237 0.69 239 237 0.691
229 5.398 229 2.589 229 5.593 239 237 6.961 239 237 6.959 239 237 6.966
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
242 5.194 242 5.123 242 5.475 244 242 12.503 244 242 11.847 245 243 0.065
Output
mass Ret_time_min mass Ret_time_min mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
I tried with a simple line: cat My.File.txt | awk '$1==$3 || $5==$1 && $8==$1 && $10==$1 && $14==$1'
but does not seems to work
text-processing awk
|
show 2 more comments
I have a file with 15 columns and I would like to filter the rows that have the same values in common in the columns number: 1,3,5,8,11,14. Basically the columns mass and artificial_mass need to have the same common value. For example from a table like this.
Input
mass Ret_time_min mass Ret_time_min mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
229 1.573 229 1.597 229 1.585 231 229 1.576 231 229 1.59 233 231 12.89
229 1.905 229 2.004 229 2.186 232 230 11.919 235 233 12.91 235 233 12.929
229 2.303 229 2.139 229 2.242 238 236 0.689 238 236 0.684 238 236 0.689
229 2.59 229 2.291 229 2.365 238 236 0.803 238 236 0.796 238 236 0.788
229 2.737 229 2.484 229 5.41 239 237 0.68 239 237 0.69 239 237 0.691
229 5.398 229 2.589 229 5.593 239 237 6.961 239 237 6.959 239 237 6.966
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
242 5.194 242 5.123 242 5.475 244 242 12.503 244 242 11.847 245 243 0.065
Output
mass Ret_time_min mass Ret_time_min mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
I tried with a simple line: cat My.File.txt | awk '$1==$3 || $5==$1 && $8==$1 && $10==$1 && $14==$1'
but does not seems to work
text-processing awk
1
Does "filter" mean "keep" or "remove"?
– Jeff Schaller
Dec 18 at 14:27
It means to keep the rows. I have modified the title.
– fusion.slope
Dec 18 at 14:35
1
Your code has several issues, first of all you have a uuoc, then your code will match any rows where$1==$3
, as you have OR condition afterwards. Then you have$10==$1
, which should be$11==$1
, other than that, it should work well. I addedNR==1
to print the header.
– RoVo
Dec 18 at 14:40
1
Don't add code to the comments, use the edit button and add it to the question
– Thor
Dec 18 at 14:48
@JeffSchaller thanks I have corrected
– fusion.slope
Dec 18 at 15:00
|
show 2 more comments
I have a file with 15 columns and I would like to filter the rows that have the same values in common in the columns number: 1,3,5,8,11,14. Basically the columns mass and artificial_mass need to have the same common value. For example from a table like this.
Input
mass Ret_time_min mass Ret_time_min mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
229 1.573 229 1.597 229 1.585 231 229 1.576 231 229 1.59 233 231 12.89
229 1.905 229 2.004 229 2.186 232 230 11.919 235 233 12.91 235 233 12.929
229 2.303 229 2.139 229 2.242 238 236 0.689 238 236 0.684 238 236 0.689
229 2.59 229 2.291 229 2.365 238 236 0.803 238 236 0.796 238 236 0.788
229 2.737 229 2.484 229 5.41 239 237 0.68 239 237 0.69 239 237 0.691
229 5.398 229 2.589 229 5.593 239 237 6.961 239 237 6.959 239 237 6.966
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
242 5.194 242 5.123 242 5.475 244 242 12.503 244 242 11.847 245 243 0.065
Output
mass Ret_time_min mass Ret_time_min mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
I tried with a simple line: cat My.File.txt | awk '$1==$3 || $5==$1 && $8==$1 && $10==$1 && $14==$1'
but does not seems to work
text-processing awk
I have a file with 15 columns and I would like to filter the rows that have the same values in common in the columns number: 1,3,5,8,11,14. Basically the columns mass and artificial_mass need to have the same common value. For example from a table like this.
Input
mass Ret_time_min mass Ret_time_min mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
229 1.573 229 1.597 229 1.585 231 229 1.576 231 229 1.59 233 231 12.89
229 1.905 229 2.004 229 2.186 232 230 11.919 235 233 12.91 235 233 12.929
229 2.303 229 2.139 229 2.242 238 236 0.689 238 236 0.684 238 236 0.689
229 2.59 229 2.291 229 2.365 238 236 0.803 238 236 0.796 238 236 0.788
229 2.737 229 2.484 229 5.41 239 237 0.68 239 237 0.69 239 237 0.691
229 5.398 229 2.589 229 5.593 239 237 6.961 239 237 6.959 239 237 6.966
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
242 5.194 242 5.123 242 5.475 244 242 12.503 244 242 11.847 245 243 0.065
Output
mass Ret_time_min mass Ret_time_min mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min mass artifical_mass Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
I tried with a simple line: cat My.File.txt | awk '$1==$3 || $5==$1 && $8==$1 && $10==$1 && $14==$1'
but does not seems to work
text-processing awk
text-processing awk
edited Dec 18 at 14:58
asked Dec 18 at 14:24
fusion.slope
360114
360114
1
Does "filter" mean "keep" or "remove"?
– Jeff Schaller
Dec 18 at 14:27
It means to keep the rows. I have modified the title.
– fusion.slope
Dec 18 at 14:35
1
Your code has several issues, first of all you have a uuoc, then your code will match any rows where$1==$3
, as you have OR condition afterwards. Then you have$10==$1
, which should be$11==$1
, other than that, it should work well. I addedNR==1
to print the header.
– RoVo
Dec 18 at 14:40
1
Don't add code to the comments, use the edit button and add it to the question
– Thor
Dec 18 at 14:48
@JeffSchaller thanks I have corrected
– fusion.slope
Dec 18 at 15:00
|
show 2 more comments
1
Does "filter" mean "keep" or "remove"?
– Jeff Schaller
Dec 18 at 14:27
It means to keep the rows. I have modified the title.
– fusion.slope
Dec 18 at 14:35
1
Your code has several issues, first of all you have a uuoc, then your code will match any rows where$1==$3
, as you have OR condition afterwards. Then you have$10==$1
, which should be$11==$1
, other than that, it should work well. I addedNR==1
to print the header.
– RoVo
Dec 18 at 14:40
1
Don't add code to the comments, use the edit button and add it to the question
– Thor
Dec 18 at 14:48
@JeffSchaller thanks I have corrected
– fusion.slope
Dec 18 at 15:00
1
1
Does "filter" mean "keep" or "remove"?
– Jeff Schaller
Dec 18 at 14:27
Does "filter" mean "keep" or "remove"?
– Jeff Schaller
Dec 18 at 14:27
It means to keep the rows. I have modified the title.
– fusion.slope
Dec 18 at 14:35
It means to keep the rows. I have modified the title.
– fusion.slope
Dec 18 at 14:35
1
1
Your code has several issues, first of all you have a uuoc, then your code will match any rows where
$1==$3
, as you have OR condition afterwards. Then you have $10==$1
, which should be $11==$1
, other than that, it should work well. I added NR==1
to print the header.– RoVo
Dec 18 at 14:40
Your code has several issues, first of all you have a uuoc, then your code will match any rows where
$1==$3
, as you have OR condition afterwards. Then you have $10==$1
, which should be $11==$1
, other than that, it should work well. I added NR==1
to print the header.– RoVo
Dec 18 at 14:40
1
1
Don't add code to the comments, use the edit button and add it to the question
– Thor
Dec 18 at 14:48
Don't add code to the comments, use the edit button and add it to the question
– Thor
Dec 18 at 14:48
@JeffSchaller thanks I have corrected
– fusion.slope
Dec 18 at 15:00
@JeffSchaller thanks I have corrected
– fusion.slope
Dec 18 at 15:00
|
show 2 more comments
1 Answer
1
active
oldest
votes
Try this,
awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file
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%2f489699%2fkeep-all-rows-according-to-common-numbers-in-specific-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this,
awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file
add a comment |
Try this,
awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file
add a comment |
Try this,
awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file
Try this,
awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file
edited Dec 18 at 14:42
answered Dec 18 at 14:35
RoVo
2,568215
2,568215
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f489699%2fkeep-all-rows-according-to-common-numbers-in-specific-columns%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
1
Does "filter" mean "keep" or "remove"?
– Jeff Schaller
Dec 18 at 14:27
It means to keep the rows. I have modified the title.
– fusion.slope
Dec 18 at 14:35
1
Your code has several issues, first of all you have a uuoc, then your code will match any rows where
$1==$3
, as you have OR condition afterwards. Then you have$10==$1
, which should be$11==$1
, other than that, it should work well. I addedNR==1
to print the header.– RoVo
Dec 18 at 14:40
1
Don't add code to the comments, use the edit button and add it to the question
– Thor
Dec 18 at 14:48
@JeffSchaller thanks I have corrected
– fusion.slope
Dec 18 at 15:00