Verify the null filed of the text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Verify the null filed of the text file
# 1  
Old 03-24-2014
Verify the null filed of the text file

Here is my sample data
Test.txt

Code:
column 1|columne 2|columne 3|columne 4
test|test||test
test|test|test|
test||test|test
test|test|test|test
|test|test|test

In that example having NULL value of the row 2-column 3,row 3-column 4,row 4 - column 2,row 6- column 1
How i can validate without open the file data rows having NULL values as staed above and print the line number.
# 2  
Old 03-24-2014
Code:
sed -n '/^|\||$\|||/=' infile

# 3  
Old 03-24-2014
Hello,

Please use the following for same.

Code:
awk -F"|" '{for(i=0;i<=NF;i++) {if($i == "") {print "field " i " have NULL Value"} {a++;} }}' file_name

Ouptut will be as follows.

Code:
field 3 have NULL Value
field 4 have NULL Value
field 2 have NULL Value
field 1 have NULL Value


Thanks,
R. Singh
# 4  
Old 03-24-2014
Hi All,
Thanks for your reply.
can you please help me to print particular column name as well.

@Ahamed101
can you please explain your code.

Last edited by krish2014; 03-24-2014 at 05:07 AM..
# 5  
Old 03-24-2014
For any column to be empty, there are 3 cases
1. | being the first character - indicating the first field is missing ^|
2. | being the last character - indicating the last field is missing |$
3. || 2 consecutive pipes indicating the some other field (apart from first and last) is missing ||

sed searches for these patterns
-n doesn't print anything unless specifically asked to
= prints the line number

HTH
# 6  
Old 03-24-2014
Try
Code:
awk    'NR==1    {split ($0, HD)}
        {for (i=0; i<=NF; i++) {if($i=="") printf "row %2d, %s\n", NR, HD[i]}}
       ' FS="|" file
row  2, columne 3
row  3, columne 4
row  4, columne 2
row  6, column 1

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace the filed at file 1 by looking the content at file 2?

Suppose I have two file which content like this: File 1.txt Cetner 1, machine A Center 2, machine B Center 3, machine A Center 4, machine C ............................ File 2.txt machine A, 10.10.10.1 machine B,... (4 Replies)
Discussion started by: Alex Li
4 Replies

2. UNIX for Dummies Questions & Answers

How to find the null member or blank in the text file?

Hello All, I am new to unix scripting and wanted to know, is it possible if we find any null value or blank record in the text file. For example we have a text file with only one column and there are 90 records. But some times we will have a null value or blank row record in the text file. I... (4 Replies)
Discussion started by: Ram11111
4 Replies

3. Shell Programming and Scripting

Verify the header and trailer in file

please see my requirement, I hope I am clear. (9 Replies)
Discussion started by: mirwasim
9 Replies

4. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

5. Infrastructure Monitoring

verify ip and port are in file

Having some problems figuring out how to do this. I have a file that has a template config for my network routers and in this config is a list of my access lists. I need help finding a way to verify if a single ip or a range along with the port allowed is in the list. My biggest issue is the range... (1 Reply)
Discussion started by: numele
1 Replies

6. Shell Programming and Scripting

filter out all the records which are having space in the 8th filed of my file

I have a file which is having fileds separtaed by delimiter. Ex: C;4498;qwa;cghy;;;;40;;222122 C;4498;sample;city;;;;34 2;;222123 C;4498;qwe;xcbv;;;;34-2;;222124 C;4498;jj;sffz;;;;41;;222120 C;4498;eert;qwq;;;;34 A;;222125 C;4498;jj;szxzzd;;;;34;;222127 out of these records I... (3 Replies)
Discussion started by: indusri
3 Replies

7. Shell Programming and Scripting

KSH script -text file processing NULL issues

I'm trying to strip any garbage that may be at the end of my text file and that part is working. The problem only seems to be with the really long lines in the file. When the head command is executed I am directing the output to a new file. The new file always get a null in the 4096 position but... (2 Replies)
Discussion started by: geauxsaints
2 Replies

8. Shell Programming and Scripting

how do i ignore rows with first filed NULL

I have a file to load in the table, and am using SQLLDR CONTROL FILE ----------------------- LOAD DATA INFILE 'sample.txt' APPEND INTO TABLE TEMP_LOAD FIELDS TERMINATED BY '|' TRAILING NULLCOLS (FIELD1,FIELD2,FIELD3) Now i have about 10,000 lines in the file FIELD1 in the table is... (1 Reply)
Discussion started by: prash184u
1 Replies

9. UNIX for Dummies Questions & Answers

How to verify weather it is a ebcdic file or not

Hi all, Please tell me how to verify weather it is a ebcdic file or not . I checked with file commond but it is giving like International Language text. Regards, Chaitu (0 Replies)
Discussion started by: c_chaitanya
0 Replies
Login or Register to Ask a Question