Check for null values in columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check for null values in columns
# 1  
Old 08-28-2012
Check for null values in columns

Hi ,

I have below data with fixed with of 52 bytes having three columns value data.

Code:
01930 MA GLOUCESTER                                 
02033                                               
02025    COHASSET                                   
01960 MA

I want if any of the column value is null .. i need to redirect that record into a seperate file

from above last three records should be stored into a seperate file

Regards
Sonu


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-28-2012 at 05:50 AM.. Reason: code tags
# 2  
Old 08-28-2012
you mean, you need to check whether 3 fields are there in the line or not ?

Code:
 
awk 'NF<3' input.txt > output.txt

# 3  
Old 08-28-2012
What have you tried so far?... Smilie
Code:
$ awk 'NF!=3' infile > outfile

# 4  
Old 08-28-2012
Assuming as per your inputs - It is having only 3 columns....

Code:
awk '{ if ( NF == 3 ) { print > Old_file } else { print > new_file } }' file3

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. Shell Programming and Scripting

Multiple columns replace with null values.

I am trying to replace the partcular columns(Col3,col5,col20,col44,col55,co56,col59,col60,col61,col62,col74,col75,col88,col90,col91,col93,col94,col95) with empty Input file Col1,col2,col3,col4,col5------,col100 1,2,3,4,5,---------,100 3,4,5,6,7,---------,300 Output : ... (3 Replies)
Discussion started by: onesuri
3 Replies

3. UNIX for Dummies Questions & Answers

Find Null values in Columns and fail execution by displaying error message

Hi All, I am new to shell scripting. I have a requirement as part of my job to find out null/empty values in column 2 and column 3 from a CSV file and exit the further execution of script by displaying a simple error message. I have developed a script to do this by reading various articles... (7 Replies)
Discussion started by: tpk
7 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 values in columns and print certain error messages if value > 10, 40 , 60

Hi Experts, I need your assistance to check values in certain columns (5 and 8 %Err) from awk o/p and if the value is > 10 print "<Minor>: <complete row>" , if value > 40 then print "<Major>: <complete row> and If value > 60 then print "<Critical>: <complete row>". and separates the repetition... (3 Replies)
Discussion started by: Dendany83
3 Replies

7. Shell Programming and Scripting

sorting null values

Hi I have a file with the values abc res set kls lmn ops i want to sort this file with the null values at the bottom of the file OUTPUT should look like this abc kls lmn ops (6 Replies)
Discussion started by: vickyhere
6 Replies

8. UNIX for Advanced & Expert Users

How to Compare Null values??

Hi, Can someone help me comparing Null values. Scenario is as follows: I have a variable which "cache_prd" which can have either some integer or nothing(Null) if it is integer I have to again do some comparision but these comparisons give me this error:( "line 32: [: 95: unary operator... (3 Replies)
Discussion started by: Yagami
3 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