some_command | cut -c26- # from the 26th character to the end of each line
some_command | cut -c1-10 # first 10 characters
some_command | cut -d: -f1,3 # colon-delimited fields 1 and 3
cut -d, -f2- file.csv # field 2 to the end
cut -d: -f3 file # third field (text between the 2nd and 3rd colon)
-d sets the delimiter (one character) and -f picks fields. cut keeps the fields in file order (-f3,1 still prints field 1 first) and treats each delimiter literally, so repeated spaces produce empty fields. For whitespace-separated columns, use awk.
Keep the last N characters (cut from the end)¶
some_command | rev | cut -c1-26 | rev # last 26 characters
some_command | rev | cut -c26- | rev # drop the last 25 characters
Pod names: pick fields from a dash-separated string¶
kubectl -n myns get pods | grep nova-conductor
nova-conductor-669568b96d6-4v8jb
nova-conductor-669568b96d6-7zjcj
kubectl -n myns get pods | grep nova-conductor | cut -d- -f3 # 669568b96d6
kubectl -n myns get pods | grep nova-conductor | cut -d- -f4 # 4v8jb
kubectl -n myns get pods -o name | cut -d/ -f2 # use -o name when possible
Splitting output from structured tools is fragile. Where a tool has -o json/-o custom-columns, use that instead.