Visit Our UNIX and Linux User Community


Find out if few fields in a file are null


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find out if few fields in a file are null
# 1  
Old 10-21-2009
Find out if few fields in a file are null

Hi,
I've a pipe delimited file where I want to find out a number of lines where 1st 2nd and last field are null using awk/sed. Is it possible?

Thanks
# 2  
Old 10-21-2009
Quote:
Originally Posted by rudoraj
Hi,
I've a pipe delimited file where I want to find out a number of lines where 1st 2nd and last field are null using awk/sed. Is it possible?
Code:
awk -F\| ' !$1 || !$2 || !$NF { print NR, "empty field" }'


Last edited by vgersh99; 10-21-2009 at 04:35 PM.. Reason: fixed a code tag
# 3  
Old 10-21-2009
Great this gives number of recrods. Would it be possible to print the lines instead?

Thanks
# 4  
Old 10-21-2009
Quote:
Originally Posted by rudoraj
Great this gives number of recrods. Would it be possible to print the lines instead?

You can put whatever you want it to do inside the braces.
# 5  
Old 10-22-2009
Code:
Wrong one, ignore it. awk -F\| '{$1=$2=$NF=""}'1 urfile

Quote:
Originally Posted by rudoraj
Great this gives number of recrods. Would it be possible to print the lines instead?

Thanks
Code:
awk -F\| ' !$1 || !$2 || !$NF { print $0 }'


Last edited by rdcwayx; 10-22-2009 at 09:18 PM..
# 6  
Old 10-22-2009
Quote:
Originally Posted by rdcwayx
Code:
awk -F\| '{$1=$2=$NF=""}'1 urfile


That assigns an empty string to those fields; it doesn't tell whether they are empty.

Previous Thread | Next Thread
Test Your Knowledge in Computers #419
Difficulty: Easy
Few popular modern Web browsers support JavaScript with built-in interpreters.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To find record having null value

Hi All My requirement is to find the null values in particular column of a file and reject it in case if it contains null values. But the challenge is that I want a common command which can be used across different file, as the position of the column we need to check for different file may get... (14 Replies)
Discussion started by: ginrkf
14 Replies

2. Shell Programming and Scripting

Fields shifting in file, do to null values?

The below code runs and creates an output file with three sections. The first 2 sections are ok, but the third section doesn't seem to put a . in all the fields that are blank. I don't know if this is what causes the last two fields in the current output to shift to a newline, but I can not seem... (3 Replies)
Discussion started by: cmccabe
3 Replies

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

4. Shell Programming and Scripting

Find fields from one file in the other file

I need to find (basically, grep) matching lines ignoring the first field from file1: field1 field2 field3 field4 field5 field6 id1 carrot white small id2 carrot id3 potato black id4 potato in file2: field1 field2 field3 field4 field5 field6 num1 carrot white ... (2 Replies)
Discussion started by: coppuca
2 Replies

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

6. Shell Programming and Scripting

Aligning output with null fields in shell script

Hello Gurus ! I have what probably amounts to a few simply changes to fix; however for the life of me I cannot seem to get it ti work. I need to align the output of my script (I am writing to a logfile)... here's the lines in my code: if then echo "NODE: $node" >> $logfile... (6 Replies)
Discussion started by: gvolpini
6 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

exclude records with null fields

Hi, can I do something like this to add a condition of checking if the 4th field is number or space or blank also: awk -F, '$4 /^*||*/' MYFILE >> OTHERFILE I also want the other part i.e. I need to exclude all lines whose 4th field is space or blank or number: MYFILE a,b,c,d,e a,b,c,2,r... (2 Replies)
Discussion started by: praveenK_Dudala
2 Replies

9. Shell Programming and Scripting

Replace 3 fields with null in the file

Hi, I have a file with 104 columns delimited by comma. I have to replace fields 4,5 and 19 with null values and after replacing the columns in the file , the file should be still comma delimited. I am new to shell scripting, Experts please help me out. Thank you (1 Reply)
Discussion started by: vukkusila
1 Replies

10. Shell Programming and Scripting

Find null fields in file

Hi All, I have some csv files out of which i want to find records which have empty values in either the 14th or 16th fields. The following is a sample. $cut -d',' -f14,16 SPS* | head -5 VOIP_ORIG_INFO,VOIP_DEST_INFO sip:445600709315@sip.com,sip:999@sip.com... (2 Replies)
Discussion started by: rahulrathod
2 Replies

Featured Tech Videos