Does the inverse command of cut exist?
As others have pointed out, you should not parse the output of ls
. Assuming you are using ls
only as an example and will be parsing something else, there are a few ways of doing what you want:
cut
with-d
and-f
cut -d ' ' -f 1,2,3,4,9
from
man cut
:-d, --delimiter=DELIM use DELIM instead of TAB for field delimiter -f, --fields=LIST select only these fields; also print any line that contains no delimiter character, unless the -s option is specified
Specifically for
ls
this is likely to fail sincels
will change the amount of whitespace between consecutive fields to make them align better.cut
treatsfoo<space>bar
andfoo<space><space>bar
differently.awk
and its variants split each input line into fields on white space so you can tell it to print only the fields you want:awk '{print $1,$2,$3,$4,$9}'
Perl
perl -lane 'print "@F[0 .. 3,8]"'
You can get the inverse of the results of cut
by using the --complement
option. The cut
man page says (somewhat unhelpfully):
--complement
complement the set of selected bytes, characters or fields
So, for instance,
$ echo The fifth and sixth words will be missing | cut -d ' ' -f 5-6 --complement
The fifth and sixth be missing
Explanation:
-d ' '
sets the delimiter to the space character-f 5-6
selects the fields 5 through 6 ("words will") to be output--complement
returns the complement (inverse) of the selected text