Check for null values in a column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Check for null values in a column
# 8  
Old 04-03-2009
Quote:
Originally Posted by nephros
Which does the exact same thing unless I'm missing something.
[...]
Is there an awk implementation/version that supports that syntax?
I mean:

Code:
awk 'FS="," { ... }'


Last edited by radoulov; 04-03-2009 at 11:18 AM..
# 9  
Old 04-03-2009
Quote:
Originally Posted by radoulov
Is there an awk implementation/version that supports that syntax?
I mean:

Code:
awk 'FS="," { ... }'

/usr/bin/nawk from Solaris 10.
# 10  
Old 04-03-2009
Quote:
Originally Posted by nephros
/usr/bin/nawk from Solaris 10.
the Solaris' '/usr/xpg4/bin/awk' takes this as well:
Code:
/usr/xpg4/bin/awk 'FS="," {if ($8 == "") print "Line", NR, "REJECTED" }' file

but it does not return anything. Reevaluating the whole record [$0=$0] does not help either.
I don't understand why though: the [FS=","] is the condition which after the assignment should evaluate to 'true' and then the following action [{if ...}] should be executed.
But it looks like the the assignment [FS=","] returns 'false' and the 'action' never executes and no 'print' get executed:
Code:
/usr/xpg4/bin/awk 'FS="," {print $0;if ($8 == "") print "Line", NR, "REJECTED" }'

Weird.......
# 11  
Old 04-03-2009
Quote:
Originally Posted by nephros
/usr/bin/nawk from Solaris 10.
Thank you!
When I read your post I did a quick test with the bell-labs awk compiled on Linux
(I thought it was quite similar to the New awk shipped with Solaris) and, as Franklin52 pointed out,
you need to force the recompilation of the current record to get the desired result.

GNU awk and mawk behave the same.

And I confirm that the New awk (/usr/bin/nawk) shipped with Solaris and awk (New awk) on HP-UX recognize it (no recompilation of the current record is needed).

The X-Open POSIX Group awk (/usr/xpg4/bin/awk on Solaris) ignores it silently. The plain old awk (/bin/awk on Solaris) complains with an error.

Solaris:

Code:
% uname -r
5.8
% awk 'FS="," { print $2 }'<<<'a,b 
c,d'
awk: syntax error near line 1
awk: bailing out near line 1
% nawk 'FS="," { print $2 }'<<<'a,b 
c,d'
b
d
% /usr/xpg4/bin/awk 'FS="," { print $2 }'<<<'a,b 
c,d'
%

Linux:

Code:
% newawk 'FS="," { print $2 }'<<<'a,b
c,d'

d
% gawk 'FS="," { print $2 }'<<<'a,b
c,d'

d
% mawk 'FS="," { print $2 }'<<<'a,b
c,d'

d


Last edited by radoulov; 04-03-2009 at 11:55 AM..
# 12  
Old 04-06-2009
Quote:
Originally Posted by Franklin52
You are missing something...Smilie
The FS is changed after the line is read, so it doesn't affect the FS in the current line in the buffer. Your solution gives all the lines of the data from the OP. To get the proper output you have to rearrange the buffer with $0=$0:

Code:
nawk '{FS=",";$0=$0;if ($8 == "") print "Line", NR, "REJECTED" }' file

Regards
Guys Thanks for the clarifications on awk n nawk.Guys you all are opening the file and reading it line by line.But how do i check whether a particular column contains atleast one NULL column without reading the file line by line..Thats my requisite.Smilie
# 13  
Old 04-06-2009
Quote:
Originally Posted by ganesh_248
Guys Thanks for the clarifications on awk n nawk.Guys you all are opening the file and reading it line by line.But how do i check whether a particular column contains atleast one NULL column without reading the file line by line..Thats my requisite.Smilie
all test unix commands like grep ,sed awk etc etc.. work on line you will get very very few commands in unix which act on full file at once so if you find any let me knowSmilie
# 14  
Old 04-06-2009
Bug

Quote:
Originally Posted by vidyadhar85
all test unix commands like grep ,sed awk etc etc.. work on line you will get very very few commands in unix which act on full file at once so if you find any let me knowSmilie
Vidyadar,i can read line by line and check whether the particular column has NULL or NOT.But i receive Huge files and they come in batches of 100's.so opening each and every file and reading it line by line consumes lot of time.I am trying out if there is any other possibility to create a shell script that is efficient and less time consuming for this problem.:-)
Please do let me know if u find any command bro' .
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check for null values in a columns. I have dozen of CSV files in a directory.

Hi Folks, I'm trying to write a simple file sanity check script. I have a directory with dozen CSV files containing id,edname,firstname,lastname,suffix,email. I like to write a awk script to check if first field contain a number and is not empty. and fields number 3,4 & 6 are not empty and... (3 Replies)
Discussion started by: dc34684
3 Replies

2. UNIX for Dummies Questions & Answers

Check for not null column in a pipe delimited file

Hi, I have a requirement where I have to check whether the mandatory columns in a pipe delimited file is null and print error message. For eg, I have to check if the 3rd,5th,6th,7th and 8th column are null and print the message "<column name> is null". The data file will have aroung 100,000... (6 Replies)
Discussion started by: reshma15193
6 Replies

3. Shell Programming and Scripting

Check increment values in column

Gents, I have a file where i would like to check the constant increment by 2 in column 2. 5450 1000 5450 1002 5450 1004 5450 1006 5465 1000 5465 1002 5465 1006 5465 1008 5550 1002 5550 1004 5550 1006 5550 1008 6830 1000 6830 1002 6830 1008 6830 1010 (6 Replies)
Discussion started by: jiam912
6 Replies

4. Shell Programming and Scripting

Script to check for null values in a column

Hi Guys, I am new to shell script.I need your help to write a shell script. I have a csv file which has 13 columns separated by , I have written below script to fetch required 5 columns. awk -F, '(NR==1){h3=$3;h4=$4;h8=$8;h9=$9;h13=$13;next}(NF>1) \ {print... (5 Replies)
Discussion started by: Vivekit82
5 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

Check to identify duplicate values at first column in csv file

Hello experts, I have a requirement where I have to implement two checks on a csv file: 1. Check to see if the value in first column is duplicate, if any value is duplicate script should exit. 2. Check to verify if the value at second column is between "yes" or "no", if it is anything else... (4 Replies)
Discussion started by: avikaljain
4 Replies

7. Shell Programming and Scripting

Check for null values in columns

Hi , I have below data with fixed with of 52 bytes having three columns value data. 01930 MA GLOUCESTER 02033 02025 COHASSET 01960 MA ... (3 Replies)
Discussion started by: sonu_pal
3 Replies

8. UNIX for Dummies Questions & Answers

shift values in one column as header for values in another column

Hi Gurus, I have a tab separated text file with two columns. I would like to make the first column values as headings for the second column values. Ex. >value1 subjects >value2 priorities >value3 requirements ...etc and I want to have a file >value1 subjects >value2 priorities... (4 Replies)
Discussion started by: Unilearn
4 Replies

9. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 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