Delete multiple columns using awk or sedsplit string with awk and delimiterFiltering a line with sedUsing Regex Breaking a text on the last digit using linux tools like sed, or awkEvaluate Expression within awkawk: matching strings to decimal values and summing themsed remove last 2 numeralsremove 2nd line of output using awkwrite a number of strings using awkBash help: awk columnsPipe stdout through sed or awk command BEFORE redirecting to file?
I found an audio circuit and I built it just fine, but I find it a bit too quiet. How do I amplify the output so that it is a bit louder?
What is the difference between lands and mana?
Is it necessary to use pronouns with the verb "essere"?
How to make money from a browser who sees 5 seconds into the future of any web page?
Doesn't the system of the Supreme Court oppose justice?
How much of a Devil Fruit must be consumed to gain the power?
When were female captains banned from Starfleet?
Why the "ls" command is showing the permissions of files in a FAT32 partition?
Why do Radio Buttons not fill the entire outer circle?
What kind of floor tile is this?
Taxes on Dividends in a Roth IRA
How do I fix the group tension caused by my character stealing and possibly killing without provocation?
Biological Blimps: Propulsion
Is it allowed to activate the ability of multiple planeswalkers in a single turn?
What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?
US tourist/student visa
Can I say "fingers" when referring to toes?
Why is the Sun approximated as a black body at ~ 5800 K?
How to convince somebody that he is fit for something else, but not this job?
Quoting Keynes in a lecture
Mimic lecturing on blackboard, facing audience
Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?
Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?
Circuit Analysis: Obtaining Close Loop OP - AMP Transfer function
Delete multiple columns using awk or sed
split string with awk and delimiterFiltering a line with sedUsing Regex Breaking a text on the last digit using linux tools like sed, or awkEvaluate Expression within awkawk: matching strings to decimal values and summing themsed remove last 2 numeralsremove 2nd line of output using awkwrite a number of strings using awkBash help: awk columnsPipe stdout through sed or awk command BEFORE redirecting to file?
I have a database with 6037 space-separated columns and 450 rows like the one below:
1807 1452 1598 1 6.655713 A B A B ... 0
1808 1452 1763 1 9.362033 0 0 A B ... A
1809 1452 1527 2 6.728534 A B A A ... B
1810 1452 1367 2 9.4055 A B A A B ... A
... ... ... ... ... ... ... ... ... ...
1812 1452 1258 1 6.363032 0 0 A B ... B
I want to get a new database with only the first 676 columns.
Preferably, some form that uses awk
or sed
command.
text-processing sed awk
New contributor
add a comment |
I have a database with 6037 space-separated columns and 450 rows like the one below:
1807 1452 1598 1 6.655713 A B A B ... 0
1808 1452 1763 1 9.362033 0 0 A B ... A
1809 1452 1527 2 6.728534 A B A A ... B
1810 1452 1367 2 9.4055 A B A A B ... A
... ... ... ... ... ... ... ... ... ...
1812 1452 1258 1 6.363032 0 0 A B ... B
I want to get a new database with only the first 676 columns.
Preferably, some form that uses awk
or sed
command.
text-processing sed awk
New contributor
The delimiter is the space.
– andrec
59 mins ago
add a comment |
I have a database with 6037 space-separated columns and 450 rows like the one below:
1807 1452 1598 1 6.655713 A B A B ... 0
1808 1452 1763 1 9.362033 0 0 A B ... A
1809 1452 1527 2 6.728534 A B A A ... B
1810 1452 1367 2 9.4055 A B A A B ... A
... ... ... ... ... ... ... ... ... ...
1812 1452 1258 1 6.363032 0 0 A B ... B
I want to get a new database with only the first 676 columns.
Preferably, some form that uses awk
or sed
command.
text-processing sed awk
New contributor
I have a database with 6037 space-separated columns and 450 rows like the one below:
1807 1452 1598 1 6.655713 A B A B ... 0
1808 1452 1763 1 9.362033 0 0 A B ... A
1809 1452 1527 2 6.728534 A B A A ... B
1810 1452 1367 2 9.4055 A B A A B ... A
... ... ... ... ... ... ... ... ... ...
1812 1452 1258 1 6.363032 0 0 A B ... B
I want to get a new database with only the first 676 columns.
Preferably, some form that uses awk
or sed
command.
text-processing sed awk
text-processing sed awk
New contributor
New contributor
edited 29 mins ago
dessert
24.7k672105
24.7k672105
New contributor
asked 2 hours ago
andrecandrec
61
61
New contributor
New contributor
The delimiter is the space.
– andrec
59 mins ago
add a comment |
The delimiter is the space.
– andrec
59 mins ago
The delimiter is the space.
– andrec
59 mins ago
The delimiter is the space.
– andrec
59 mins ago
add a comment |
2 Answers
2
active
oldest
votes
If the column delimiter in your file is a single character, e.g. a space, cut
can do that easily:
cut -d' ' -f-676 <in >out
This prints only the space-separated columns from the first to the 676th.
If you need e.g. every whitespace character to count as a delimiter, a sed
solution is:
sed -r 's/s+S+//677g' <in >out
This replaces every column (= at least one whitespace character followed by at least one non-whitespace character) beginning with the 677th with nothing. Using character groups you can specify any set of delimiters you need, e.g. for “4”, “#” and “K”:
sed -r 's/[4#K]+[^4#K]+//677g' <in >out
For a reasonable awk
approach kindly refer to steeldriver’s answer, but here is another one looping over the columns and only printing them (separated by FS
) if their number is <= 676:
awk 'for (i=1;i<=676;i++) printf (i==1?"":FS)$i; print ""' <in >out
For a character group you have to specify the output field separator for the output, e.g. for [4#K]
and "sep"
:
awk -F'[4#K]' 'for (i=1;i<=676;i++) printf (i==1?"":"sep")$i; print ""' <in >out
add a comment |
For a single-character delimiter (such as space or comma) I would recommend using the cut
command over either awk
or sed
.
However since you asked about awk
specifically, I think a reasonable way to do it would be to decrement the field count:
awk -v last=676 'while(NF>last) NF-- 1' datafile
Tested in GNU Awk (gawk
) and mawk
.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
);
);
andrec is a new contributor. Be nice, and check out our Code of Conduct.
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%2faskubuntu.com%2fquestions%2f1127670%2fdelete-multiple-columns-using-awk-or-sed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If the column delimiter in your file is a single character, e.g. a space, cut
can do that easily:
cut -d' ' -f-676 <in >out
This prints only the space-separated columns from the first to the 676th.
If you need e.g. every whitespace character to count as a delimiter, a sed
solution is:
sed -r 's/s+S+//677g' <in >out
This replaces every column (= at least one whitespace character followed by at least one non-whitespace character) beginning with the 677th with nothing. Using character groups you can specify any set of delimiters you need, e.g. for “4”, “#” and “K”:
sed -r 's/[4#K]+[^4#K]+//677g' <in >out
For a reasonable awk
approach kindly refer to steeldriver’s answer, but here is another one looping over the columns and only printing them (separated by FS
) if their number is <= 676:
awk 'for (i=1;i<=676;i++) printf (i==1?"":FS)$i; print ""' <in >out
For a character group you have to specify the output field separator for the output, e.g. for [4#K]
and "sep"
:
awk -F'[4#K]' 'for (i=1;i<=676;i++) printf (i==1?"":"sep")$i; print ""' <in >out
add a comment |
If the column delimiter in your file is a single character, e.g. a space, cut
can do that easily:
cut -d' ' -f-676 <in >out
This prints only the space-separated columns from the first to the 676th.
If you need e.g. every whitespace character to count as a delimiter, a sed
solution is:
sed -r 's/s+S+//677g' <in >out
This replaces every column (= at least one whitespace character followed by at least one non-whitespace character) beginning with the 677th with nothing. Using character groups you can specify any set of delimiters you need, e.g. for “4”, “#” and “K”:
sed -r 's/[4#K]+[^4#K]+//677g' <in >out
For a reasonable awk
approach kindly refer to steeldriver’s answer, but here is another one looping over the columns and only printing them (separated by FS
) if their number is <= 676:
awk 'for (i=1;i<=676;i++) printf (i==1?"":FS)$i; print ""' <in >out
For a character group you have to specify the output field separator for the output, e.g. for [4#K]
and "sep"
:
awk -F'[4#K]' 'for (i=1;i<=676;i++) printf (i==1?"":"sep")$i; print ""' <in >out
add a comment |
If the column delimiter in your file is a single character, e.g. a space, cut
can do that easily:
cut -d' ' -f-676 <in >out
This prints only the space-separated columns from the first to the 676th.
If you need e.g. every whitespace character to count as a delimiter, a sed
solution is:
sed -r 's/s+S+//677g' <in >out
This replaces every column (= at least one whitespace character followed by at least one non-whitespace character) beginning with the 677th with nothing. Using character groups you can specify any set of delimiters you need, e.g. for “4”, “#” and “K”:
sed -r 's/[4#K]+[^4#K]+//677g' <in >out
For a reasonable awk
approach kindly refer to steeldriver’s answer, but here is another one looping over the columns and only printing them (separated by FS
) if their number is <= 676:
awk 'for (i=1;i<=676;i++) printf (i==1?"":FS)$i; print ""' <in >out
For a character group you have to specify the output field separator for the output, e.g. for [4#K]
and "sep"
:
awk -F'[4#K]' 'for (i=1;i<=676;i++) printf (i==1?"":"sep")$i; print ""' <in >out
If the column delimiter in your file is a single character, e.g. a space, cut
can do that easily:
cut -d' ' -f-676 <in >out
This prints only the space-separated columns from the first to the 676th.
If you need e.g. every whitespace character to count as a delimiter, a sed
solution is:
sed -r 's/s+S+//677g' <in >out
This replaces every column (= at least one whitespace character followed by at least one non-whitespace character) beginning with the 677th with nothing. Using character groups you can specify any set of delimiters you need, e.g. for “4”, “#” and “K”:
sed -r 's/[4#K]+[^4#K]+//677g' <in >out
For a reasonable awk
approach kindly refer to steeldriver’s answer, but here is another one looping over the columns and only printing them (separated by FS
) if their number is <= 676:
awk 'for (i=1;i<=676;i++) printf (i==1?"":FS)$i; print ""' <in >out
For a character group you have to specify the output field separator for the output, e.g. for [4#K]
and "sep"
:
awk -F'[4#K]' 'for (i=1;i<=676;i++) printf (i==1?"":"sep")$i; print ""' <in >out
edited 1 hour ago
answered 2 hours ago
dessertdessert
24.7k672105
24.7k672105
add a comment |
add a comment |
For a single-character delimiter (such as space or comma) I would recommend using the cut
command over either awk
or sed
.
However since you asked about awk
specifically, I think a reasonable way to do it would be to decrement the field count:
awk -v last=676 'while(NF>last) NF-- 1' datafile
Tested in GNU Awk (gawk
) and mawk
.
add a comment |
For a single-character delimiter (such as space or comma) I would recommend using the cut
command over either awk
or sed
.
However since you asked about awk
specifically, I think a reasonable way to do it would be to decrement the field count:
awk -v last=676 'while(NF>last) NF-- 1' datafile
Tested in GNU Awk (gawk
) and mawk
.
add a comment |
For a single-character delimiter (such as space or comma) I would recommend using the cut
command over either awk
or sed
.
However since you asked about awk
specifically, I think a reasonable way to do it would be to decrement the field count:
awk -v last=676 'while(NF>last) NF-- 1' datafile
Tested in GNU Awk (gawk
) and mawk
.
For a single-character delimiter (such as space or comma) I would recommend using the cut
command over either awk
or sed
.
However since you asked about awk
specifically, I think a reasonable way to do it would be to decrement the field count:
awk -v last=676 'while(NF>last) NF-- 1' datafile
Tested in GNU Awk (gawk
) and mawk
.
edited 47 mins ago
answered 1 hour ago
steeldriversteeldriver
69.8k11114186
69.8k11114186
add a comment |
add a comment |
andrec is a new contributor. Be nice, and check out our Code of Conduct.
andrec is a new contributor. Be nice, and check out our Code of Conduct.
andrec is a new contributor. Be nice, and check out our Code of Conduct.
andrec is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1127670%2fdelete-multiple-columns-using-awk-or-sed%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
The delimiter is the space.
– andrec
59 mins ago