How to sort or order results docker ps --format?
I haven't found any way to order my results when using docker ps
In my case I want to order by .Ports
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}"
How do I order the result?
docker
add a comment |
I haven't found any way to order my results when using docker ps
In my case I want to order by .Ports
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}"
How do I order the result?
docker
if you pipe and sort it? or have a look at Andy'answer from Docker Inspect Template Magic from Adrian Mouat container-solutions.com/docker-inspect-template-magic I guess you look for a docker only solution
– user2915097
Sep 12 '17 at 10:41
I don't think you can do anything golang template specific to do this. You need to build your own stuff for this. What may work is hitting the API and usingjq
to sort results and display. But not sure how easy that would be
– Tarun Lalwani
Sep 12 '17 at 11:38
from webgeodatavore.com/… I seeSort only value, not the object (return array)
andjq '[.features.properties.pop_est] | sort' countries.geojson
so I guess this is possible with jq (I do not have a docke ravailable at the moment, I will test later)
– user2915097
Sep 12 '17 at 11:48
andjq -R .|jq -sr 'sort_by(length)'
sort by length from reddit.com/r/commandline/comments/3z9jff/jq_examples
– user2915097
Sep 12 '17 at 11:49
see also stackoverflow.com/questions/43930011/… for a similar basicdocker command | sort
and ther is an issue on that subject, see github.com/moby/moby/issues/31062
– user2915097
Sep 12 '17 at 13:24
add a comment |
I haven't found any way to order my results when using docker ps
In my case I want to order by .Ports
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}"
How do I order the result?
docker
I haven't found any way to order my results when using docker ps
In my case I want to order by .Ports
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}"
How do I order the result?
docker
docker
edited Dec 7 '17 at 9:47
Thodi
asked Sep 12 '17 at 9:54
ThodiThodi
148113
148113
if you pipe and sort it? or have a look at Andy'answer from Docker Inspect Template Magic from Adrian Mouat container-solutions.com/docker-inspect-template-magic I guess you look for a docker only solution
– user2915097
Sep 12 '17 at 10:41
I don't think you can do anything golang template specific to do this. You need to build your own stuff for this. What may work is hitting the API and usingjq
to sort results and display. But not sure how easy that would be
– Tarun Lalwani
Sep 12 '17 at 11:38
from webgeodatavore.com/… I seeSort only value, not the object (return array)
andjq '[.features.properties.pop_est] | sort' countries.geojson
so I guess this is possible with jq (I do not have a docke ravailable at the moment, I will test later)
– user2915097
Sep 12 '17 at 11:48
andjq -R .|jq -sr 'sort_by(length)'
sort by length from reddit.com/r/commandline/comments/3z9jff/jq_examples
– user2915097
Sep 12 '17 at 11:49
see also stackoverflow.com/questions/43930011/… for a similar basicdocker command | sort
and ther is an issue on that subject, see github.com/moby/moby/issues/31062
– user2915097
Sep 12 '17 at 13:24
add a comment |
if you pipe and sort it? or have a look at Andy'answer from Docker Inspect Template Magic from Adrian Mouat container-solutions.com/docker-inspect-template-magic I guess you look for a docker only solution
– user2915097
Sep 12 '17 at 10:41
I don't think you can do anything golang template specific to do this. You need to build your own stuff for this. What may work is hitting the API and usingjq
to sort results and display. But not sure how easy that would be
– Tarun Lalwani
Sep 12 '17 at 11:38
from webgeodatavore.com/… I seeSort only value, not the object (return array)
andjq '[.features.properties.pop_est] | sort' countries.geojson
so I guess this is possible with jq (I do not have a docke ravailable at the moment, I will test later)
– user2915097
Sep 12 '17 at 11:48
andjq -R .|jq -sr 'sort_by(length)'
sort by length from reddit.com/r/commandline/comments/3z9jff/jq_examples
– user2915097
Sep 12 '17 at 11:49
see also stackoverflow.com/questions/43930011/… for a similar basicdocker command | sort
and ther is an issue on that subject, see github.com/moby/moby/issues/31062
– user2915097
Sep 12 '17 at 13:24
if you pipe and sort it? or have a look at Andy'answer from Docker Inspect Template Magic from Adrian Mouat container-solutions.com/docker-inspect-template-magic I guess you look for a docker only solution
– user2915097
Sep 12 '17 at 10:41
if you pipe and sort it? or have a look at Andy'answer from Docker Inspect Template Magic from Adrian Mouat container-solutions.com/docker-inspect-template-magic I guess you look for a docker only solution
– user2915097
Sep 12 '17 at 10:41
I don't think you can do anything golang template specific to do this. You need to build your own stuff for this. What may work is hitting the API and using
jq
to sort results and display. But not sure how easy that would be– Tarun Lalwani
Sep 12 '17 at 11:38
I don't think you can do anything golang template specific to do this. You need to build your own stuff for this. What may work is hitting the API and using
jq
to sort results and display. But not sure how easy that would be– Tarun Lalwani
Sep 12 '17 at 11:38
from webgeodatavore.com/… I see
Sort only value, not the object (return array)
and jq '[.features.properties.pop_est] | sort' countries.geojson
so I guess this is possible with jq (I do not have a docke ravailable at the moment, I will test later)– user2915097
Sep 12 '17 at 11:48
from webgeodatavore.com/… I see
Sort only value, not the object (return array)
and jq '[.features.properties.pop_est] | sort' countries.geojson
so I guess this is possible with jq (I do not have a docke ravailable at the moment, I will test later)– user2915097
Sep 12 '17 at 11:48
and
jq -R .|jq -sr 'sort_by(length)'
sort by length from reddit.com/r/commandline/comments/3z9jff/jq_examples– user2915097
Sep 12 '17 at 11:49
and
jq -R .|jq -sr 'sort_by(length)'
sort by length from reddit.com/r/commandline/comments/3z9jff/jq_examples– user2915097
Sep 12 '17 at 11:49
see also stackoverflow.com/questions/43930011/… for a similar basic
docker command | sort
and ther is an issue on that subject, see github.com/moby/moby/issues/31062– user2915097
Sep 12 '17 at 13:24
see also stackoverflow.com/questions/43930011/… for a similar basic
docker command | sort
and ther is an issue on that subject, see github.com/moby/moby/issues/31062– user2915097
Sep 12 '17 at 13:24
add a comment |
3 Answers
3
active
oldest
votes
If it's enough to simply sort by output column, you can use the following:
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}" | (read -r; printf "%sn" "$REPLY"; sort -k 3 )
I also added a code for skipping the table headers and sorting only ps output data.
add a comment |
Format and Order docker ps
List containers
docker ps
Synopsis
docker ps [--format="TEMPLATE"]
--format="TEMPLATE"
Pretty-print containers using a Go template.
Valid placeholders:
.ID - Container ID
.Image - Image ID
.Command - Quoted command
.CreatedAt - Time when the container was created.
.RunningFor - Elapsed time since the container was started.
.Ports - Exposed ports.
.Status - Container status.
.Size - Container disk size.
.Names - Container names.
.Labels - All labels assigned to the container.
.Label - Value of a specific label for this container. For example {{.Label "com.docker.swarm.cpu"}}
.Mounts - Names of the volumes mounted in this container.
Display containers with their commands
docker ps --format "{{.ID}}: {{.Command}}"
Display containers with their labels in a table
docker ps --format "table {{.ID}}t{{.Labels}}"
Display containers with their node label in a table
docker ps --format 'table {{.ID}}t{{(.Label "com.docker.swarm.node")}}'
add a comment |
I built a docker ps pretty print function that can be put into your .bash_profile
or .bashrc
file that works somewhat like an alias for docker ps
(with color output). @art-rock-guitar-superhero suggestions shows how to sort, but I've included this answer since typing the --format
options and piping into a sort
every time is a bit tedious.
function docker () {
if [[ "$@" == "ps -p" ]]; then
command docker ps --all --format "{{.ID}}t{{.Names}}t{{.Image}}t{{.Ports}}t{{.Status}}"
| (echo -e "CONTAINER_IDtNAMEStIMAGEtPORTStSTATUS" && cat)
| awk '{printf "33[1;32m%st33[01;38;5;95;38;5;196m%st33[00m33[1;34m%st33[01;90m%s %s %s %s %s %s %s33[00mn", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10;}'
| column -s$'t' -t
| awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
else
command docker "$@"
fi
}
usage: $ docker ps -p
.
EDIT: I added suggestions from the comments from @BrianVosburgh. Also, I kept forgetting to type -p
so I switched the flag for this function to be -a
, which is my regular usage of docker ps
.
1
Nice function. : ) But I think there is an extraneous backslash in the 'awk' pattern:...196m%st...
should read...196m%st...
.
– Brian Vosburgh
Nov 13 '18 at 17:41
1
Also, you could sort the table with something like this:docker ps -p | awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
– Brian Vosburgh
Nov 13 '18 at 17:59
@BrianVosburgh, yes, thanks, I removed the extraneous backslash. I'm not sure why, but it had no impact on the output. Also, the extra stuff to sort by second column (key) of name, is a nice suggestion as well, and so I've updated the original answer with your sort command.
– David John Coleman II
Nov 21 '18 at 13:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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%2fstackoverflow.com%2fquestions%2f46173298%2fhow-to-sort-or-order-results-docker-ps-format%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
If it's enough to simply sort by output column, you can use the following:
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}" | (read -r; printf "%sn" "$REPLY"; sort -k 3 )
I also added a code for skipping the table headers and sorting only ps output data.
add a comment |
If it's enough to simply sort by output column, you can use the following:
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}" | (read -r; printf "%sn" "$REPLY"; sort -k 3 )
I also added a code for skipping the table headers and sorting only ps output data.
add a comment |
If it's enough to simply sort by output column, you can use the following:
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}" | (read -r; printf "%sn" "$REPLY"; sort -k 3 )
I also added a code for skipping the table headers and sorting only ps output data.
If it's enough to simply sort by output column, you can use the following:
docker ps -a --format "table {{.ID}}t{{.Names}}t{{.Ports}}" | (read -r; printf "%sn" "$REPLY"; sort -k 3 )
I also added a code for skipping the table headers and sorting only ps output data.
edited Apr 23 '18 at 5:47
Rob♦
23.8k115575
23.8k115575
answered Apr 23 '18 at 3:43
Art-Rock Guitar SuperheroArt-Rock Guitar Superhero
8117
8117
add a comment |
add a comment |
Format and Order docker ps
List containers
docker ps
Synopsis
docker ps [--format="TEMPLATE"]
--format="TEMPLATE"
Pretty-print containers using a Go template.
Valid placeholders:
.ID - Container ID
.Image - Image ID
.Command - Quoted command
.CreatedAt - Time when the container was created.
.RunningFor - Elapsed time since the container was started.
.Ports - Exposed ports.
.Status - Container status.
.Size - Container disk size.
.Names - Container names.
.Labels - All labels assigned to the container.
.Label - Value of a specific label for this container. For example {{.Label "com.docker.swarm.cpu"}}
.Mounts - Names of the volumes mounted in this container.
Display containers with their commands
docker ps --format "{{.ID}}: {{.Command}}"
Display containers with their labels in a table
docker ps --format "table {{.ID}}t{{.Labels}}"
Display containers with their node label in a table
docker ps --format 'table {{.ID}}t{{(.Label "com.docker.swarm.node")}}'
add a comment |
Format and Order docker ps
List containers
docker ps
Synopsis
docker ps [--format="TEMPLATE"]
--format="TEMPLATE"
Pretty-print containers using a Go template.
Valid placeholders:
.ID - Container ID
.Image - Image ID
.Command - Quoted command
.CreatedAt - Time when the container was created.
.RunningFor - Elapsed time since the container was started.
.Ports - Exposed ports.
.Status - Container status.
.Size - Container disk size.
.Names - Container names.
.Labels - All labels assigned to the container.
.Label - Value of a specific label for this container. For example {{.Label "com.docker.swarm.cpu"}}
.Mounts - Names of the volumes mounted in this container.
Display containers with their commands
docker ps --format "{{.ID}}: {{.Command}}"
Display containers with their labels in a table
docker ps --format "table {{.ID}}t{{.Labels}}"
Display containers with their node label in a table
docker ps --format 'table {{.ID}}t{{(.Label "com.docker.swarm.node")}}'
add a comment |
Format and Order docker ps
List containers
docker ps
Synopsis
docker ps [--format="TEMPLATE"]
--format="TEMPLATE"
Pretty-print containers using a Go template.
Valid placeholders:
.ID - Container ID
.Image - Image ID
.Command - Quoted command
.CreatedAt - Time when the container was created.
.RunningFor - Elapsed time since the container was started.
.Ports - Exposed ports.
.Status - Container status.
.Size - Container disk size.
.Names - Container names.
.Labels - All labels assigned to the container.
.Label - Value of a specific label for this container. For example {{.Label "com.docker.swarm.cpu"}}
.Mounts - Names of the volumes mounted in this container.
Display containers with their commands
docker ps --format "{{.ID}}: {{.Command}}"
Display containers with their labels in a table
docker ps --format "table {{.ID}}t{{.Labels}}"
Display containers with their node label in a table
docker ps --format 'table {{.ID}}t{{(.Label "com.docker.swarm.node")}}'
Format and Order docker ps
List containers
docker ps
Synopsis
docker ps [--format="TEMPLATE"]
--format="TEMPLATE"
Pretty-print containers using a Go template.
Valid placeholders:
.ID - Container ID
.Image - Image ID
.Command - Quoted command
.CreatedAt - Time when the container was created.
.RunningFor - Elapsed time since the container was started.
.Ports - Exposed ports.
.Status - Container status.
.Size - Container disk size.
.Names - Container names.
.Labels - All labels assigned to the container.
.Label - Value of a specific label for this container. For example {{.Label "com.docker.swarm.cpu"}}
.Mounts - Names of the volumes mounted in this container.
Display containers with their commands
docker ps --format "{{.ID}}: {{.Command}}"
Display containers with their labels in a table
docker ps --format "table {{.ID}}t{{.Labels}}"
Display containers with their node label in a table
docker ps --format 'table {{.ID}}t{{(.Label "com.docker.swarm.node")}}'
edited Oct 2 '18 at 0:32
answered Sep 12 '17 at 13:45
Jinna BaluJinna Balu
1,2871118
1,2871118
add a comment |
add a comment |
I built a docker ps pretty print function that can be put into your .bash_profile
or .bashrc
file that works somewhat like an alias for docker ps
(with color output). @art-rock-guitar-superhero suggestions shows how to sort, but I've included this answer since typing the --format
options and piping into a sort
every time is a bit tedious.
function docker () {
if [[ "$@" == "ps -p" ]]; then
command docker ps --all --format "{{.ID}}t{{.Names}}t{{.Image}}t{{.Ports}}t{{.Status}}"
| (echo -e "CONTAINER_IDtNAMEStIMAGEtPORTStSTATUS" && cat)
| awk '{printf "33[1;32m%st33[01;38;5;95;38;5;196m%st33[00m33[1;34m%st33[01;90m%s %s %s %s %s %s %s33[00mn", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10;}'
| column -s$'t' -t
| awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
else
command docker "$@"
fi
}
usage: $ docker ps -p
.
EDIT: I added suggestions from the comments from @BrianVosburgh. Also, I kept forgetting to type -p
so I switched the flag for this function to be -a
, which is my regular usage of docker ps
.
1
Nice function. : ) But I think there is an extraneous backslash in the 'awk' pattern:...196m%st...
should read...196m%st...
.
– Brian Vosburgh
Nov 13 '18 at 17:41
1
Also, you could sort the table with something like this:docker ps -p | awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
– Brian Vosburgh
Nov 13 '18 at 17:59
@BrianVosburgh, yes, thanks, I removed the extraneous backslash. I'm not sure why, but it had no impact on the output. Also, the extra stuff to sort by second column (key) of name, is a nice suggestion as well, and so I've updated the original answer with your sort command.
– David John Coleman II
Nov 21 '18 at 13:23
add a comment |
I built a docker ps pretty print function that can be put into your .bash_profile
or .bashrc
file that works somewhat like an alias for docker ps
(with color output). @art-rock-guitar-superhero suggestions shows how to sort, but I've included this answer since typing the --format
options and piping into a sort
every time is a bit tedious.
function docker () {
if [[ "$@" == "ps -p" ]]; then
command docker ps --all --format "{{.ID}}t{{.Names}}t{{.Image}}t{{.Ports}}t{{.Status}}"
| (echo -e "CONTAINER_IDtNAMEStIMAGEtPORTStSTATUS" && cat)
| awk '{printf "33[1;32m%st33[01;38;5;95;38;5;196m%st33[00m33[1;34m%st33[01;90m%s %s %s %s %s %s %s33[00mn", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10;}'
| column -s$'t' -t
| awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
else
command docker "$@"
fi
}
usage: $ docker ps -p
.
EDIT: I added suggestions from the comments from @BrianVosburgh. Also, I kept forgetting to type -p
so I switched the flag for this function to be -a
, which is my regular usage of docker ps
.
1
Nice function. : ) But I think there is an extraneous backslash in the 'awk' pattern:...196m%st...
should read...196m%st...
.
– Brian Vosburgh
Nov 13 '18 at 17:41
1
Also, you could sort the table with something like this:docker ps -p | awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
– Brian Vosburgh
Nov 13 '18 at 17:59
@BrianVosburgh, yes, thanks, I removed the extraneous backslash. I'm not sure why, but it had no impact on the output. Also, the extra stuff to sort by second column (key) of name, is a nice suggestion as well, and so I've updated the original answer with your sort command.
– David John Coleman II
Nov 21 '18 at 13:23
add a comment |
I built a docker ps pretty print function that can be put into your .bash_profile
or .bashrc
file that works somewhat like an alias for docker ps
(with color output). @art-rock-guitar-superhero suggestions shows how to sort, but I've included this answer since typing the --format
options and piping into a sort
every time is a bit tedious.
function docker () {
if [[ "$@" == "ps -p" ]]; then
command docker ps --all --format "{{.ID}}t{{.Names}}t{{.Image}}t{{.Ports}}t{{.Status}}"
| (echo -e "CONTAINER_IDtNAMEStIMAGEtPORTStSTATUS" && cat)
| awk '{printf "33[1;32m%st33[01;38;5;95;38;5;196m%st33[00m33[1;34m%st33[01;90m%s %s %s %s %s %s %s33[00mn", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10;}'
| column -s$'t' -t
| awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
else
command docker "$@"
fi
}
usage: $ docker ps -p
.
EDIT: I added suggestions from the comments from @BrianVosburgh. Also, I kept forgetting to type -p
so I switched the flag for this function to be -a
, which is my regular usage of docker ps
.
I built a docker ps pretty print function that can be put into your .bash_profile
or .bashrc
file that works somewhat like an alias for docker ps
(with color output). @art-rock-guitar-superhero suggestions shows how to sort, but I've included this answer since typing the --format
options and piping into a sort
every time is a bit tedious.
function docker () {
if [[ "$@" == "ps -p" ]]; then
command docker ps --all --format "{{.ID}}t{{.Names}}t{{.Image}}t{{.Ports}}t{{.Status}}"
| (echo -e "CONTAINER_IDtNAMEStIMAGEtPORTStSTATUS" && cat)
| awk '{printf "33[1;32m%st33[01;38;5;95;38;5;196m%st33[00m33[1;34m%st33[01;90m%s %s %s %s %s %s %s33[00mn", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10;}'
| column -s$'t' -t
| awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
else
command docker "$@"
fi
}
usage: $ docker ps -p
.
EDIT: I added suggestions from the comments from @BrianVosburgh. Also, I kept forgetting to type -p
so I switched the flag for this function to be -a
, which is my regular usage of docker ps
.
edited Nov 28 '18 at 4:02
answered Oct 20 '18 at 18:21
David John Coleman IIDavid John Coleman II
350410
350410
1
Nice function. : ) But I think there is an extraneous backslash in the 'awk' pattern:...196m%st...
should read...196m%st...
.
– Brian Vosburgh
Nov 13 '18 at 17:41
1
Also, you could sort the table with something like this:docker ps -p | awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
– Brian Vosburgh
Nov 13 '18 at 17:59
@BrianVosburgh, yes, thanks, I removed the extraneous backslash. I'm not sure why, but it had no impact on the output. Also, the extra stuff to sort by second column (key) of name, is a nice suggestion as well, and so I've updated the original answer with your sort command.
– David John Coleman II
Nov 21 '18 at 13:23
add a comment |
1
Nice function. : ) But I think there is an extraneous backslash in the 'awk' pattern:...196m%st...
should read...196m%st...
.
– Brian Vosburgh
Nov 13 '18 at 17:41
1
Also, you could sort the table with something like this:docker ps -p | awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
– Brian Vosburgh
Nov 13 '18 at 17:59
@BrianVosburgh, yes, thanks, I removed the extraneous backslash. I'm not sure why, but it had no impact on the output. Also, the extra stuff to sort by second column (key) of name, is a nice suggestion as well, and so I've updated the original answer with your sort command.
– David John Coleman II
Nov 21 '18 at 13:23
1
1
Nice function. : ) But I think there is an extraneous backslash in the 'awk' pattern:
...196m%st...
should read ...196m%st...
.– Brian Vosburgh
Nov 13 '18 at 17:41
Nice function. : ) But I think there is an extraneous backslash in the 'awk' pattern:
...196m%st...
should read ...196m%st...
.– Brian Vosburgh
Nov 13 '18 at 17:41
1
1
Also, you could sort the table with something like this:
docker ps -p | awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
– Brian Vosburgh
Nov 13 '18 at 17:59
Also, you could sort the table with something like this:
docker ps -p | awk 'NR<2{print $0;next}{print $0 | "sort --key=2"}'
– Brian Vosburgh
Nov 13 '18 at 17:59
@BrianVosburgh, yes, thanks, I removed the extraneous backslash. I'm not sure why, but it had no impact on the output. Also, the extra stuff to sort by second column (key) of name, is a nice suggestion as well, and so I've updated the original answer with your sort command.
– David John Coleman II
Nov 21 '18 at 13:23
@BrianVosburgh, yes, thanks, I removed the extraneous backslash. I'm not sure why, but it had no impact on the output. Also, the extra stuff to sort by second column (key) of name, is a nice suggestion as well, and so I've updated the original answer with your sort command.
– David John Coleman II
Nov 21 '18 at 13:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f46173298%2fhow-to-sort-or-order-results-docker-ps-format%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
if you pipe and sort it? or have a look at Andy'answer from Docker Inspect Template Magic from Adrian Mouat container-solutions.com/docker-inspect-template-magic I guess you look for a docker only solution
– user2915097
Sep 12 '17 at 10:41
I don't think you can do anything golang template specific to do this. You need to build your own stuff for this. What may work is hitting the API and using
jq
to sort results and display. But not sure how easy that would be– Tarun Lalwani
Sep 12 '17 at 11:38
from webgeodatavore.com/… I see
Sort only value, not the object (return array)
andjq '[.features.properties.pop_est] | sort' countries.geojson
so I guess this is possible with jq (I do not have a docke ravailable at the moment, I will test later)– user2915097
Sep 12 '17 at 11:48
and
jq -R .|jq -sr 'sort_by(length)'
sort by length from reddit.com/r/commandline/comments/3z9jff/jq_examples– user2915097
Sep 12 '17 at 11:49
see also stackoverflow.com/questions/43930011/… for a similar basic
docker command | sort
and ther is an issue on that subject, see github.com/moby/moby/issues/31062– user2915097
Sep 12 '17 at 13:24