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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find Null values in Columns and fail execution by displaying error message
# 8  
Old 04-08-2015
Two of your requirements (excluding headers and exit with code 16 if fields 2 or 3 are empty in a file) can be fulfilled easily with
Code:
awk     'function PR()  {print FILENAME, V?": Null values " V:": All records good."}

         FNR==1         {next}
         !$2            {V=102}
         !$3            {V=103}

         FNR==2 && NR>2 {PR(); if (V) exit 16}

        ' FS="," pf_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].csv

Unfortunately, awk doesn't know if it is operationg on the last line of a file, so we'd need to save each line and then check for FNR==1 (or the END condition). Try yourself and come back if you hit a brick wall.
 
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. Shell Programming and Scripting

Find for line with not null values at nth place in pipe delimited file

Hi, I am trying to find the lines in a pipe delimited file where 11th column has not null values. Any help is appreciated. Need help asap please. thanks in advance. (3 Replies)
Discussion started by: manikms
3 Replies

4. UNIX for Dummies Questions & Answers

Eliminate error message (/dev/null)?

I am trying to eliminate an error message from a script. This is the error message: find: stat() error /usr/openv/netbackup/db/images/KUMAX: No such file or directory if ]; then runthiscommand=`su nxadm -c "ssh -t $new3 exec /bin/sh -s">/tmp/filew3 2>/tmp/error.txt<<EOF ... (1 Reply)
Discussion started by: newbie2010
1 Replies

5. UNIX for Dummies Questions & Answers

Find duplicated values in two columns out of three

hi! could u help in the following? I have the data (long list!) that looks like (three coumns white space separated): rs3094315 0.0665173 742429 rs12562034 0.0738998 758311 rs3934834 0.396449 995669 rs9442372 0.402693 1008567 rs3737728 0.406271 1011278 rs6687776 0.435429 1020428 rs9651273... (4 Replies)
Discussion started by: kush
4 Replies

6. 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

7. Shell Programming and Scripting

How to list Matching Directories OR NULL w/o error message?

I want to be able to get all the directories in a path into a variable array, BUT if there ARE NO directories I want the Variable to be NULL and not echo any error message! If there ARE directories, this will get the list of the directories whose name begins with the string "20":... (6 Replies)
Discussion started by: pgorbas
6 Replies

8. Shell Programming and Scripting

find error?? find / -name "something.txt" 2>/dev/null

why is this giving me errors? i type this in: find / -name "something.txt" 2>/dev/null i get the following error messages: find: bad option 2 find: path-list predicate-list :confused: (5 Replies)
Discussion started by: magiling
5 Replies

9. Shell Programming and Scripting

Need to return fail or pass from shell script on the basis of pl/sql code execution

Hi guys, I am quite new in shell scripting. I am tring to promote some oracle jobs into control-M. In control-M, I am calling a script which establishes a connection with database and execute some procedures. Now I want if that PL/sql Block got failed script should return failure to... (2 Replies)
Discussion started by: alok1301
2 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
type(1) 						      General Commands Manual							   type(1)

NAME
type - Writes a description of command type SYNOPSIS
type name... STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: type: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
A name to be interpreted DESCRIPTION
The type utility indicates how each argument would be interpreted if used as a command name. The standard output of type contains information about each parameter. The information provided identifies the operand as a shell built-in, a function, an alias or keyword, and where applicable, displays the command's pathname. RESTRICTIONS
For proper execution, type must be aware of the contents of the current shell execution environment (such as the lists of commands, func- tions and built-ins processed by hash). If type is called in a separate utility execution environment, such as one of the following it might not produce accurate results. nohup type writer find . -type f | xargs type EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. ENVIRONMENT VARIABLES
The following environment variables affect the execution of type: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contains an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. Determines the location of name. SEE ALSO
Commands: command(1), hash(1) Standards: standards(5) type(1)