How to find how many values in a column are not present
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "."
For example
car.txt
Car Colour mpg Year
vw_golf blue 56 2006
vw_polo red 66 2010
honda_civic white . 2007
ford_ka red . 2014
So the ones I'm interested in are the honda civic and ford ka as they don't have a number present for the mpg column and I want to find out how many values in the mpg column which doesn't have a value (in this case is 2).
The problem I'm having is the period seems to give errors when I use awk command.
linux text-processing awk grep
add a comment |Â
up vote
1
down vote
favorite
I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "."
For example
car.txt
Car Colour mpg Year
vw_golf blue 56 2006
vw_polo red 66 2010
honda_civic white . 2007
ford_ka red . 2014
So the ones I'm interested in are the honda civic and ford ka as they don't have a number present for the mpg column and I want to find out how many values in the mpg column which doesn't have a value (in this case is 2).
The problem I'm having is the period seems to give errors when I use awk command.
linux text-processing awk grep
1
awk '$3 ~ /./ count++ ENDprint count' file
â jasonwryan
Nov 19 '17 at 22:02
@jasonwryan that should probably be$3 == "."
(else it will count decimal mpgs like66.3
as well)
â steeldriver
Nov 19 '17 at 22:09
@steeldriver good point.
â jasonwryan
Nov 19 '17 at 22:10
@jasonwryan so u mean awk '$3 =="." ' file?
â Maurice
Nov 19 '17 at 22:13
Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
â Jeff Schaller
Apr 28 at 11:50
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "."
For example
car.txt
Car Colour mpg Year
vw_golf blue 56 2006
vw_polo red 66 2010
honda_civic white . 2007
ford_ka red . 2014
So the ones I'm interested in are the honda civic and ford ka as they don't have a number present for the mpg column and I want to find out how many values in the mpg column which doesn't have a value (in this case is 2).
The problem I'm having is the period seems to give errors when I use awk command.
linux text-processing awk grep
I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "."
For example
car.txt
Car Colour mpg Year
vw_golf blue 56 2006
vw_polo red 66 2010
honda_civic white . 2007
ford_ka red . 2014
So the ones I'm interested in are the honda civic and ford ka as they don't have a number present for the mpg column and I want to find out how many values in the mpg column which doesn't have a value (in this case is 2).
The problem I'm having is the period seems to give errors when I use awk command.
linux text-processing awk grep
edited Nov 19 '17 at 22:41
Jeff Schaller
32.1k849109
32.1k849109
asked Nov 19 '17 at 21:59
Maurice
132
132
1
awk '$3 ~ /./ count++ ENDprint count' file
â jasonwryan
Nov 19 '17 at 22:02
@jasonwryan that should probably be$3 == "."
(else it will count decimal mpgs like66.3
as well)
â steeldriver
Nov 19 '17 at 22:09
@steeldriver good point.
â jasonwryan
Nov 19 '17 at 22:10
@jasonwryan so u mean awk '$3 =="." ' file?
â Maurice
Nov 19 '17 at 22:13
Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
â Jeff Schaller
Apr 28 at 11:50
add a comment |Â
1
awk '$3 ~ /./ count++ ENDprint count' file
â jasonwryan
Nov 19 '17 at 22:02
@jasonwryan that should probably be$3 == "."
(else it will count decimal mpgs like66.3
as well)
â steeldriver
Nov 19 '17 at 22:09
@steeldriver good point.
â jasonwryan
Nov 19 '17 at 22:10
@jasonwryan so u mean awk '$3 =="." ' file?
â Maurice
Nov 19 '17 at 22:13
Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
â Jeff Schaller
Apr 28 at 11:50
1
1
awk '$3 ~ /./ count++ ENDprint count' file
â jasonwryan
Nov 19 '17 at 22:02
awk '$3 ~ /./ count++ ENDprint count' file
â jasonwryan
Nov 19 '17 at 22:02
@jasonwryan that should probably be
$3 == "."
(else it will count decimal mpgs like 66.3
as well)â steeldriver
Nov 19 '17 at 22:09
@jasonwryan that should probably be
$3 == "."
(else it will count decimal mpgs like 66.3
as well)â steeldriver
Nov 19 '17 at 22:09
@steeldriver good point.
â jasonwryan
Nov 19 '17 at 22:10
@steeldriver good point.
â jasonwryan
Nov 19 '17 at 22:10
@jasonwryan so u mean awk '$3 =="." ' file?
â Maurice
Nov 19 '17 at 22:13
@jasonwryan so u mean awk '$3 =="." ' file?
â Maurice
Nov 19 '17 at 22:13
Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
â Jeff Schaller
Apr 28 at 11:50
Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
â Jeff Schaller
Apr 28 at 11:50
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
Short grep
approach:
grep -Ec '^S+s+S+s+.s+' file
2
-E
- allow extended regular expressions-c
- print a count of matching linesS+
- match non-whitespace character(s), it is a synonym for[^[:space:]]
s+
- match whitespace character(s), it is a synonym for[[:space:]]
add a comment |Â
up vote
0
down vote
Another grep
method, if your file is strictly formatted to have the mpg start at column 28:
$ grep '............................' input
honda_civic white . 2007
ford_ka red . 2014
$ grep -c '............................' input
2
That's 28 periods (for "any" character) followed by an escaped period ("a period").
Or with awk
, as mentioned in the comments:
$ awk '$3 == "."' input
honda_civic white . 2007
ford_ka red . 2014
$ awk '$3 == "."' input | wc -l
2
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Short grep
approach:
grep -Ec '^S+s+S+s+.s+' file
2
-E
- allow extended regular expressions-c
- print a count of matching linesS+
- match non-whitespace character(s), it is a synonym for[^[:space:]]
s+
- match whitespace character(s), it is a synonym for[[:space:]]
add a comment |Â
up vote
0
down vote
Short grep
approach:
grep -Ec '^S+s+S+s+.s+' file
2
-E
- allow extended regular expressions-c
- print a count of matching linesS+
- match non-whitespace character(s), it is a synonym for[^[:space:]]
s+
- match whitespace character(s), it is a synonym for[[:space:]]
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Short grep
approach:
grep -Ec '^S+s+S+s+.s+' file
2
-E
- allow extended regular expressions-c
- print a count of matching linesS+
- match non-whitespace character(s), it is a synonym for[^[:space:]]
s+
- match whitespace character(s), it is a synonym for[[:space:]]
Short grep
approach:
grep -Ec '^S+s+S+s+.s+' file
2
-E
- allow extended regular expressions-c
- print a count of matching linesS+
- match non-whitespace character(s), it is a synonym for[^[:space:]]
s+
- match whitespace character(s), it is a synonym for[[:space:]]
answered Nov 19 '17 at 22:29
RomanPerekhrest
22.4k12145
22.4k12145
add a comment |Â
add a comment |Â
up vote
0
down vote
Another grep
method, if your file is strictly formatted to have the mpg start at column 28:
$ grep '............................' input
honda_civic white . 2007
ford_ka red . 2014
$ grep -c '............................' input
2
That's 28 periods (for "any" character) followed by an escaped period ("a period").
Or with awk
, as mentioned in the comments:
$ awk '$3 == "."' input
honda_civic white . 2007
ford_ka red . 2014
$ awk '$3 == "."' input | wc -l
2
add a comment |Â
up vote
0
down vote
Another grep
method, if your file is strictly formatted to have the mpg start at column 28:
$ grep '............................' input
honda_civic white . 2007
ford_ka red . 2014
$ grep -c '............................' input
2
That's 28 periods (for "any" character) followed by an escaped period ("a period").
Or with awk
, as mentioned in the comments:
$ awk '$3 == "."' input
honda_civic white . 2007
ford_ka red . 2014
$ awk '$3 == "."' input | wc -l
2
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Another grep
method, if your file is strictly formatted to have the mpg start at column 28:
$ grep '............................' input
honda_civic white . 2007
ford_ka red . 2014
$ grep -c '............................' input
2
That's 28 periods (for "any" character) followed by an escaped period ("a period").
Or with awk
, as mentioned in the comments:
$ awk '$3 == "."' input
honda_civic white . 2007
ford_ka red . 2014
$ awk '$3 == "."' input | wc -l
2
Another grep
method, if your file is strictly formatted to have the mpg start at column 28:
$ grep '............................' input
honda_civic white . 2007
ford_ka red . 2014
$ grep -c '............................' input
2
That's 28 periods (for "any" character) followed by an escaped period ("a period").
Or with awk
, as mentioned in the comments:
$ awk '$3 == "."' input
honda_civic white . 2007
ford_ka red . 2014
$ awk '$3 == "."' input | wc -l
2
answered Apr 13 at 16:32
Jeff Schaller
32.1k849109
32.1k849109
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f405667%2fhow-to-find-how-many-values-in-a-column-are-not-present%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
awk '$3 ~ /./ count++ ENDprint count' file
â jasonwryan
Nov 19 '17 at 22:02
@jasonwryan that should probably be
$3 == "."
(else it will count decimal mpgs like66.3
as well)â steeldriver
Nov 19 '17 at 22:09
@steeldriver good point.
â jasonwryan
Nov 19 '17 at 22:10
@jasonwryan so u mean awk '$3 =="." ' file?
â Maurice
Nov 19 '17 at 22:13
Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
â Jeff Schaller
Apr 28 at 11:50