Originally Posted by
CantankRus
anyone care to explain this...in particular what a delimiter is?
delimiter can be anything defined in a script to break up a line into "sections" or fields or in this case defined within "cut"
If ; was defined as a delimiter:
or tabs:
that way one can use just a certain part of a line.
Been staring me in the face since forever but it took syntaxerror74 to put focus on it ...
Shows us:
Code:
-c, --characters=LIST
select only these characters
-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
... among other things of course:
-f --field = field
What I got use to and stuck with was -c --character.
But "field" is much neater:
Code:
24 Aug 14 | 10:31:11 ~
$ grep 'model ' /proc/cpuinfo | cut -f1- '-d '
model name : AMD Athlon(tm) II X3 450 Processor
model name : AMD Athlon(tm) II X3 450 Processor
model name : AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:32:08 ~
$ grep 'model ' /proc/cpuinfo | cut -f2- '-d '
name : AMD Athlon(tm) II X3 450 Processor
name : AMD Athlon(tm) II X3 450 Processor
name : AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:32:19 ~
$ grep 'model ' /proc/cpuinfo | cut -f3- '-d '
AMD Athlon(tm) II X3 450 Processor
AMD Athlon(tm) II X3 450 Processor
AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:32:27 ~
$
--character
Code:
24 Aug 14 | 10:38:10 ~
$ grep 'model ' /proc/cpuinfo |cut -c 1-
model name : AMD Athlon(tm) II X3 450 Processor
model name : AMD Athlon(tm) II X3 450 Processor
model name : AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:38:18 ~
$ grep 'model ' /proc/cpuinfo |cut -c 3-
del name : AMD Athlon(tm) II X3 450 Processor
del name : AMD Athlon(tm) II X3 450 Processor
del name : AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:38:27 ~
$ grep 'model ' /proc/cpuinfo |cut -c 10-
e : AMD Athlon(tm) II X3 450 Processor
e : AMD Athlon(tm) II X3 450 Processor
e : AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:38:35 ~
$ grep 'model ' /proc/cpuinfo |cut -c 12-
: AMD Athlon(tm) II X3 450 Processor
: AMD Athlon(tm) II X3 450 Processor
: AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:38:48 ~
$ grep 'model ' /proc/cpuinfo |cut -c 13-
AMD Athlon(tm) II X3 450 Processor
AMD Athlon(tm) II X3 450 Processor
AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:38:54 ~
$ grep 'model ' /proc/cpuinfo |cut -c 14-
AMD Athlon(tm) II X3 450 Processor
AMD Athlon(tm) II X3 450 Processor
AMD Athlon(tm) II X3 450 Processor
24 Aug 14 | 10:38:59 ~
$ grep 'model ' /proc/cpuinfo |cut -c 14-23
AMD Athlon
AMD Athlon
AMD Athlon
24 Aug 14 | 10:39:35 ~
$ grep 'model ' /proc/cpuinfo |cut -c 14-23|uniq
AMD Athlon
24 Aug 14 | 10:39:47 ~
$
Which I guess is just as short. Either way, it got rid of sed
Bookmarks