ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi all
I am looking for the solution to delete the entire row from a file if it matches a 'null' value in a particular column.
suppose for example , I have a file
one two three four
five six eight
nine ten eleven
one two four
from the above file, i have to delete the row whose 3rd column is 'null'. i.e. in the above example, it has to remove 2nd and 4th row as it contains null in 3rd column. not the 3rd row as it contains null in 4th column.
the way you describe the file, there does not appear to be any difference between the last 3 rows (lines)--ie what character is there where say the "null" is. (maybe ascii 0x00?).
Awk reads into records using a delimiter to define the boundaries. In this case, it would presumably default to "space" as the default. After reading a line, simply run a test on the four records: $1, $2, $3, and $4
Actually I have given space in between the columns. But it is combined with the next column. Let me explain the problem clearly.
I have file with 50 columns and value of many columns are null(it is not in order).I need to delete the whole row whereever the value of the 30th column is null.Many columns may have null value.But i want to delete the row which has the 30th column null value. Hope everyone got the problem now.
I dont have gawk in my system.
please help me to solve this with awk.
Hi all
I am looking for the solution to delete the entire row from a file if it matches a 'null' value in a particular column.
suppose for example , I have a file
one two three four
five six eight
nine ten eleven
one two four
from the above file, i have to delete the row whose 3rd column is 'null'. i.e. in the above example, it has to remove 2nd and 4th row as it contains null in 3rd column. not the 3rd row as it contains null in 4th column.
please help me to do it
Thanks in advance
if your delimiter is a blank space(or tab), awk would not know where where null value is. The only way i can think of now is getting the correct number of fields, check the number of fields in each row and compare against the actual value. However, this method, you will only know which rows have null values, but would not know which columns. ( i may be wrong though ).
Its best if you could get your source to change to some other delimiters, such as commas...
if your delimiter is a blank space(or tab), awk would not know where where null value is. The only way i can think of now is getting the correct number of fields, check the number of fields in each row and compare against the actual value. However, this method, you will only know which rows have null values, but would not know which columns. ( i may be wrong though ).
Its best if you could get your source to change to some other delimiters, such as commas...
Yes.That is the problem now.If it is other delimeter, it is very easy to make it. also each row may have null value in different columns.so it is very diffult to use number of columns also.
Is it need to have this big coding?. Can't we do it in a single line command? becos awk is meant for it. is it not?
it depends on the complexity of your problem. Also, cramming code that is meant to solve complex problems into single line does not equate to being "cool". It makes code unreadable and difficult to troubleshoot.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.