For example, the cut
command can take a parameter -f, which according to man
select only these fields; also print any line that contains no
delimiter character, unless the -s option is specified
In this context, what is a field?
cutlinux
For example, the cut
command can take a parameter -f, which according to man
select only these fields; also print any line that contains no
delimiter character, unless the -s option is specified
In this context, what is a field?
Best Answer
The term "field" is often times associated with tools such as
cut
andawk
. A field would be similar to a columns worth of data, if you take the data and separate it using a specific character. Typically the character used to do this is a Space.However as is the case with most tools, it's configurable. For example:
awk -F"," ...
- would separate by commas (i.e. ,).cut -d"," ...
- would separate by commas (i.e. ,).Examples
This first one shows how
awk
automatically will split on spaces.This one shows how
cut
will split on spaces too.Here we have a CSV list of column data that we're using
cut
to return columns 1 & 4.Awk too can do this:
Awk is also a little more adept at dealing with a variety of separation characters. Here it's dealing with Tabs along with Spaces where they're inter-mixed at the same time:
What about the -s switch to cut?
With respect to this switch, it's simply telling
cut
to not print any lines which do not contain the delimiter character specified via the-d
switch.Example
Say we had this file.
NOTE: There are spaces and tabs in the 2nd string above.
Now when we process these strings using
cut
with and without the-s
switch:In the 2nd example you can see that the
-s
switch has omitted any strings from the output that do not contain the delimiter, Space.