[SOLVED] Find the null value in the frist column of a csv file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
grep is designed for testing lines for patterns. So if all we want is to check whether a line begins with a comma or something, it's a good choice.
But for more complex work on field-delimited text, awk is usually better. To test whether a given field contains (or doesn't contain) a certain value, just use expressions like this:
So in the first example, if field one matches the exact value of "" (i.e. nothing), then awk will print it.
( And since print is the default action on affirmative tests, it's unnecessary to include it here. I've left it off of the remaining examples ).
In the second, the "~" tests the string against a regular expression, and the regex "^$" means "string start+string end", with nothing between them. So it will only print on empty fields.
In the third one, the "!" means "not", and so reverses the test, and "." is the regex for "any single character". So again, if the field is empty (doesn't have any characters) it will print.
Finally, instead of a comparison test, we might also be able to use a simple Boolean test. If field one is empty or set to "0" (the integer zero), it will print. (Zero and null values evaluate as false in a Boolean tests. Any other value evaluates as true. And of course "!" reverses the outcome.)