How to find null column?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find null column?
# 1  
Old 01-16-2014
How to find null column?

hi Gurus,

I need find the null column in a file.
my file like below
Code:
abc, ,cde,def
abc,ded,cdd,def
abc, ,ddd,ccd
aaa,bbb,ccc,ddd

basic, I need to find the lines which second column is null

Thanks in advance
# 2  
Old 01-16-2014
Try:
Code:
awk -F, '$2==" "' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 01-16-2014
Quote:
Originally Posted by ken6503
hi Gurus,

I need find the null column in a file.
my file like below
Code:
abc, ,cde,def
abc,ded,cdd,def
abc, ,ddd,ccd
aaa,bbb,ccc,ddd

basic, I need to find the lines which second column is null

Thanks in advance
The code bartus11 suggested may be what you want; but you need to be careful with your terminology. By definition a null value does not contain any characters. Assuming that comma is your field separator, this file does not contain any null values. The 2nd field in the 1st and 3rd lines appears to contain a space character. If your file had been:
Code:
abc,,cde,def
abc,ded,cdd,def
abc,,ddd,ccd
aaa,bbb,ccc,ddd

then you could use the awk script:
Code:
awk -F, '$2 == ""' file

to print the lines where the 2nd field is an empty string (null value). Of course there are lots of other ways to do this too.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 01-16-2014
Quote:
Originally Posted by Don Cragun
The code bartus11 suggested may be what you want; but you need to be careful with your terminology. By definition a null value does not contain any characters. Assuming that comma is your field separator, this file does not contain any null values. The 2nd field in the 1st and 3rd lines appears to contain a space character. If your file had been:
Code:
abc,,cde,def
abc,ded,cdd,def
abc,,ddd,ccd
aaa,bbb,ccc,ddd

then you could use the awk script:
Code:
awk -F, '$2 == ""' file

to print the lines where the 2nd field is an empty string (null value). Of course there are lots of other ways to do this too.
Thanks for you explanation. actually, in my file, it has some space.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Divide the value of the column if not NULL.

File 1 --------- N_ACCT,CARD_TYPE,CARD_BAL,CUST_CODE --------------------------------------------------- 0301,38,0.00,10 0319,38,54422.92,10 0392,38,0.00,10 0418,38,35254.87,10 0442,38,0.00,10 0491,38,0.00,10 0558,38,45988.76,10 0616,38,0.00,10 0665,38,0.00,10 0699,38,0.00,10 File 2... (3 Replies)
Discussion started by: suresh_target
3 Replies

2. UNIX for Dummies Questions & Answers

Getting the lines with nth column non-null

Hi, I have a huge list of archives (.gz). Each archive is about 40MB. A file is generated every minute so if I want to analyze the data for 1 hour I get already 60 files for example. These are text files, ';' separated, each line having about 300 fields (columns). What I need to do is to... (11 Replies)
Discussion started by: Nenad
11 Replies

3. Shell Programming and Scripting

Finding null column value using array

hi, Am trying to find a solution for finding a null column value inside a loop using array. for eg: two three five From the above array myarray,myarray and myarray having null values. But when am trying to check that space using some condition its not working. for (( i=0;... (4 Replies)
Discussion started by: rogerben
4 Replies

4. Shell Programming and Scripting

Replace Null with 0 in 6th column in file

Hi Forum. I tried to search for the solution online but I couldn't find specifically what I'm trying to achieve. I want to replace Null with 0 in column position#6; Any other values would be retained. Before: 52653363|3407732947|28-MAR-2014... (3 Replies)
Discussion started by: pchang
3 Replies

5. Shell Programming and Scripting

Check null values column

hi, I had a small question.I had a file from which i need to extract data. I have written the below script to check if the file exists and if it exists extract requierd columns from the file. IFILE=/home/home01/Report_1.csv OFILE=/home/home01/name.csv.out1 if #Checks if file exists... (1 Reply)
Discussion started by: Vivekit82
1 Replies

6. Shell Programming and Scripting

Remove null in certain column

Hi, gurus, I need remove lines in a file which contains null value in certain column eg. 123, ,abc,def,cde 234,abc,cde,def 456,cde, ,bcd in this file I need remove lines which second column contains null. expected result: 234,abc,cde,def 456,cde, ,bcd :wall: Thanks in advance (2 Replies)
Discussion started by: ken002
2 Replies

7. Shell Programming and Scripting

how to find null column

Hi, everyone I have a requirement as following: source file 1, abc, def, caaa 2, , cde, aaa 3, bcd, , adefefg I need find columns which contains null value, in above example, I need get two rows 2, , cde, aaa 3, bcd, , adefefg anybody has idea how to achive this ... (5 Replies)
Discussion started by: ken002
5 Replies

8. Shell Programming and Scripting

Find and replace a column that has '' to NULL in a comma delimited using awk or sed

Hi this is my first time posting ever. I'm relatively new in using AWK/SED, I've been trying many a solution. I'm trying to replace the 59th column in a file where if I encounter '' then I would like to replace it with the word NULL. example 0 , '' , '' , 0 , 195.538462 change it to 0... (5 Replies)
Discussion started by: gumal901
5 Replies

9. UNIX for Dummies Questions & Answers

Check for null values in a column

Hi All, I have a file with 10 columns and get the required data for nine columns properly except 8th. In 8th column i have both NULL and NON NULL values...i.e certain records have values for all the columns including 8th column and certain records have 8th column as NULL.My requisite is,without... (20 Replies)
Discussion started by: ganesh_248
20 Replies

10. Shell Programming and Scripting

How to check Null values in a file column by column if columns are Not NULLs

Hi All, I have a table with 10 columns. Some columns(2nd,4th,5th,7th,8th and 10th) are Not Null columns. I'll get a tab-delimited file and want to check col by col and generate seperate error code for each col eg:102 if 2nd col value is NULL and 104 if 4th col value is NULL so on... I am a... (7 Replies)
Discussion started by: Mandab
7 Replies
Login or Register to Ask a Question