What is the difference between cut’s -b and -c option?
I've searched online for examples, went through the reference manual of the cut command and tested it myself and remain unsure about the -b flag. There aren't any clear examples as to how the cut -b command works. Can someone create an example file and show how it is clearly used?
command-line coreutils
add a comment |
I've searched online for examples, went through the reference manual of the cut command and tested it myself and remain unsure about the -b flag. There aren't any clear examples as to how the cut -b command works. Can someone create an example file and show how it is clearly used?
command-line coreutils
AFAIK it's currently no different fromcut -c(since GNU Coreutils doesn't yet provide support for multi-byte characters)
– steeldriver
Dec 16 '18 at 3:49
What are you unsure about?
– muru
Dec 16 '18 at 4:30
See manpages.ubuntu.com/manpages/bionic/en/man1/cut.1.html .
– N0rbert
Dec 16 '18 at 8:31
add a comment |
I've searched online for examples, went through the reference manual of the cut command and tested it myself and remain unsure about the -b flag. There aren't any clear examples as to how the cut -b command works. Can someone create an example file and show how it is clearly used?
command-line coreutils
I've searched online for examples, went through the reference manual of the cut command and tested it myself and remain unsure about the -b flag. There aren't any clear examples as to how the cut -b command works. Can someone create an example file and show how it is clearly used?
command-line coreutils
command-line coreutils
edited Dec 16 '18 at 15:04
dessert
22.2k56198
22.2k56198
asked Dec 16 '18 at 3:27
ghost
62
62
AFAIK it's currently no different fromcut -c(since GNU Coreutils doesn't yet provide support for multi-byte characters)
– steeldriver
Dec 16 '18 at 3:49
What are you unsure about?
– muru
Dec 16 '18 at 4:30
See manpages.ubuntu.com/manpages/bionic/en/man1/cut.1.html .
– N0rbert
Dec 16 '18 at 8:31
add a comment |
AFAIK it's currently no different fromcut -c(since GNU Coreutils doesn't yet provide support for multi-byte characters)
– steeldriver
Dec 16 '18 at 3:49
What are you unsure about?
– muru
Dec 16 '18 at 4:30
See manpages.ubuntu.com/manpages/bionic/en/man1/cut.1.html .
– N0rbert
Dec 16 '18 at 8:31
AFAIK it's currently no different from
cut -c (since GNU Coreutils doesn't yet provide support for multi-byte characters)– steeldriver
Dec 16 '18 at 3:49
AFAIK it's currently no different from
cut -c (since GNU Coreutils doesn't yet provide support for multi-byte characters)– steeldriver
Dec 16 '18 at 3:49
What are you unsure about?
– muru
Dec 16 '18 at 4:30
What are you unsure about?
– muru
Dec 16 '18 at 4:30
See manpages.ubuntu.com/manpages/bionic/en/man1/cut.1.html .
– N0rbert
Dec 16 '18 at 8:31
See manpages.ubuntu.com/manpages/bionic/en/man1/cut.1.html .
– N0rbert
Dec 16 '18 at 8:31
add a comment |
1 Answer
1
active
oldest
votes
GNU software is described in info pages, so let’s see what info cut says:
‘-b BYTE-LIST’ ‘--bytes=BYTE-LIST’
Select for printing only the bytes in positions listed in
BYTE-LIST. Tabs and backspaces are treated like any other
character; they take up 1 byte. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
‘-c CHARACTER-LIST’ ‘--characters=CHARACTER-LIST’
Select for printing only the characters in positions listed in
CHARACTER-LIST. The same as ‘-b’ for now, but internationalization
will change that. Tabs and backspaces are treated like any other
character; they take up 1 character. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
This is from coreutils 8.28 that comes with Ubuntu 18.04 and 18.10, adding multibyte support is in progress and may enable a different behaviour of these two options in the future.
xxd -g1 shows hexdump byte equivalents of characters (after the colon) grouped bytewise as well as its ASCII representation on the left. Take as an example:
$ printf a | xxd -g1
00000000: 61 a
$ printf á | xxd -g1
00000000: c3 a1 ..
a is a single-byte character with the hex equivalent 61, while á is a two-byte character with the hex equivalent c3 a1. Let’s see how cut from coreutils 8.28 behaves if we try to cut out the first byte or character respectively (0a is just a newline char added by cut and can be ignored):
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -c2 | xxd -g1
00000000: a1 0a .. # second byte of á
When it’s implemented, the expected behaviour is:
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 a1 0a ... # both bytes of á
$ printf áb | cut -c2 | xxd -g1
00000000: 62 0a b. # second char = b
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
});
}
});
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%2f1102240%2fwhat-is-the-difference-between-cut-s-b-and-c-option%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
GNU software is described in info pages, so let’s see what info cut says:
‘-b BYTE-LIST’ ‘--bytes=BYTE-LIST’
Select for printing only the bytes in positions listed in
BYTE-LIST. Tabs and backspaces are treated like any other
character; they take up 1 byte. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
‘-c CHARACTER-LIST’ ‘--characters=CHARACTER-LIST’
Select for printing only the characters in positions listed in
CHARACTER-LIST. The same as ‘-b’ for now, but internationalization
will change that. Tabs and backspaces are treated like any other
character; they take up 1 character. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
This is from coreutils 8.28 that comes with Ubuntu 18.04 and 18.10, adding multibyte support is in progress and may enable a different behaviour of these two options in the future.
xxd -g1 shows hexdump byte equivalents of characters (after the colon) grouped bytewise as well as its ASCII representation on the left. Take as an example:
$ printf a | xxd -g1
00000000: 61 a
$ printf á | xxd -g1
00000000: c3 a1 ..
a is a single-byte character with the hex equivalent 61, while á is a two-byte character with the hex equivalent c3 a1. Let’s see how cut from coreutils 8.28 behaves if we try to cut out the first byte or character respectively (0a is just a newline char added by cut and can be ignored):
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -c2 | xxd -g1
00000000: a1 0a .. # second byte of á
When it’s implemented, the expected behaviour is:
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 a1 0a ... # both bytes of á
$ printf áb | cut -c2 | xxd -g1
00000000: 62 0a b. # second char = b
add a comment |
GNU software is described in info pages, so let’s see what info cut says:
‘-b BYTE-LIST’ ‘--bytes=BYTE-LIST’
Select for printing only the bytes in positions listed in
BYTE-LIST. Tabs and backspaces are treated like any other
character; they take up 1 byte. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
‘-c CHARACTER-LIST’ ‘--characters=CHARACTER-LIST’
Select for printing only the characters in positions listed in
CHARACTER-LIST. The same as ‘-b’ for now, but internationalization
will change that. Tabs and backspaces are treated like any other
character; they take up 1 character. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
This is from coreutils 8.28 that comes with Ubuntu 18.04 and 18.10, adding multibyte support is in progress and may enable a different behaviour of these two options in the future.
xxd -g1 shows hexdump byte equivalents of characters (after the colon) grouped bytewise as well as its ASCII representation on the left. Take as an example:
$ printf a | xxd -g1
00000000: 61 a
$ printf á | xxd -g1
00000000: c3 a1 ..
a is a single-byte character with the hex equivalent 61, while á is a two-byte character with the hex equivalent c3 a1. Let’s see how cut from coreutils 8.28 behaves if we try to cut out the first byte or character respectively (0a is just a newline char added by cut and can be ignored):
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -c2 | xxd -g1
00000000: a1 0a .. # second byte of á
When it’s implemented, the expected behaviour is:
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 a1 0a ... # both bytes of á
$ printf áb | cut -c2 | xxd -g1
00000000: 62 0a b. # second char = b
add a comment |
GNU software is described in info pages, so let’s see what info cut says:
‘-b BYTE-LIST’ ‘--bytes=BYTE-LIST’
Select for printing only the bytes in positions listed in
BYTE-LIST. Tabs and backspaces are treated like any other
character; they take up 1 byte. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
‘-c CHARACTER-LIST’ ‘--characters=CHARACTER-LIST’
Select for printing only the characters in positions listed in
CHARACTER-LIST. The same as ‘-b’ for now, but internationalization
will change that. Tabs and backspaces are treated like any other
character; they take up 1 character. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
This is from coreutils 8.28 that comes with Ubuntu 18.04 and 18.10, adding multibyte support is in progress and may enable a different behaviour of these two options in the future.
xxd -g1 shows hexdump byte equivalents of characters (after the colon) grouped bytewise as well as its ASCII representation on the left. Take as an example:
$ printf a | xxd -g1
00000000: 61 a
$ printf á | xxd -g1
00000000: c3 a1 ..
a is a single-byte character with the hex equivalent 61, while á is a two-byte character with the hex equivalent c3 a1. Let’s see how cut from coreutils 8.28 behaves if we try to cut out the first byte or character respectively (0a is just a newline char added by cut and can be ignored):
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -c2 | xxd -g1
00000000: a1 0a .. # second byte of á
When it’s implemented, the expected behaviour is:
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 a1 0a ... # both bytes of á
$ printf áb | cut -c2 | xxd -g1
00000000: 62 0a b. # second char = b
GNU software is described in info pages, so let’s see what info cut says:
‘-b BYTE-LIST’ ‘--bytes=BYTE-LIST’
Select for printing only the bytes in positions listed in
BYTE-LIST. Tabs and backspaces are treated like any other
character; they take up 1 byte. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
‘-c CHARACTER-LIST’ ‘--characters=CHARACTER-LIST’
Select for printing only the characters in positions listed in
CHARACTER-LIST. The same as ‘-b’ for now, but internationalization
will change that. Tabs and backspaces are treated like any other
character; they take up 1 character. If an output delimiter is
specified, (see the description of ‘--output-delimiter’), then
output that string between ranges of selected bytes.
This is from coreutils 8.28 that comes with Ubuntu 18.04 and 18.10, adding multibyte support is in progress and may enable a different behaviour of these two options in the future.
xxd -g1 shows hexdump byte equivalents of characters (after the colon) grouped bytewise as well as its ASCII representation on the left. Take as an example:
$ printf a | xxd -g1
00000000: 61 a
$ printf á | xxd -g1
00000000: c3 a1 ..
a is a single-byte character with the hex equivalent 61, while á is a two-byte character with the hex equivalent c3 a1. Let’s see how cut from coreutils 8.28 behaves if we try to cut out the first byte or character respectively (0a is just a newline char added by cut and can be ignored):
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -c2 | xxd -g1
00000000: a1 0a .. # second byte of á
When it’s implemented, the expected behaviour is:
$ printf ab | cut -b1 | xxd -g1
00000000: 61 0a a.
$ printf ab | cut -c1 | xxd -g1
00000000: 61 0a a.
$ printf áb | cut -b1 | xxd -g1
00000000: c3 0a .. # first byte of á
$ printf áb | cut -b2 | xxd -g1
00000000: a1 0a .. # second byte of á
$ printf áb | cut -c1 | xxd -g1
00000000: c3 a1 0a ... # both bytes of á
$ printf áb | cut -c2 | xxd -g1
00000000: 62 0a b. # second char = b
edited Dec 16 '18 at 14:58
answered Dec 16 '18 at 10:42
dessert
22.2k56198
22.2k56198
add a comment |
add a comment |
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.
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%2faskubuntu.com%2fquestions%2f1102240%2fwhat-is-the-difference-between-cut-s-b-and-c-option%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
AFAIK it's currently no different from
cut -c(since GNU Coreutils doesn't yet provide support for multi-byte characters)– steeldriver
Dec 16 '18 at 3:49
What are you unsure about?
– muru
Dec 16 '18 at 4:30
See manpages.ubuntu.com/manpages/bionic/en/man1/cut.1.html .
– N0rbert
Dec 16 '18 at 8:31