I want to show only specific columns for all the records in the command.
Example: docker ps
shows me data in 10 columns. It can have space in between the column headers. My requirement is to get only 2-4 columns in some sequence.
Is there a direct way to do that in any of the commands that respond in a tabular way?
I am new to Linux and thinking if this can be feasible. Thanks.
For example:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED NAMES
123 image "ABC DEF" 10 hours ago image ABC
Here in the above scenario, CONTAINER ID
is one header column but there is space, and in the row for NAMES
columns can have space in between.
Using AWK
, CUT
etc it is trickier to write a common script for all the commands because they work on "space" logic.
One way to find duplicate records from the table is the GROUP BY statement. The GROUP BY statement in SQL is used to arrange identical data into groups with the help of some functions. i.e if a particular column has the same values in different rows then it will arrange these rows in a group.
Select one or more cells in a range, table, or PivotTable report. On the Home tab, in the Styles group, click the arrow for Conditional Formatting, and then click Manage Rules to display the Conditional Formatting Rules Manager popup window. Under Select a Rule Type, click Format only unique or duplicate values.
Select the range of cells, or make sure that the active cell is in a table. On the Data tab, in the Data Tools group, click Remove Duplicates. Select one or more of the check boxes, which refer to columns in the table, and then click Remove Duplicates.
Piping the output to tr and cut:
docker ps | tr -s " " | cut -d " " -f 2-4
-s flag on tr squeezes characters and leaves only one " "
-d on cut tells to split field by " ".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With