Here is my sample data
Test.txt
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.
sed -n '/^|\||$\|||/=' infile
Hello,
Please use the following for same.
awk -F"|" '{for(i=0;i<=NF;i++) {if($i == "") {print "field " i " have NULL Value"} {a++;} }}' file_name
Ouptut will be as follows.
field 3 have NULL Value
field 4 have NULL Value
field 2 have NULL Value
field 1 have NULL Value
Thanks,
R. Singh
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.
For any column to be empty, there are 3 cases
| being the first character - indicating the first field is missing ^|
| being the last character - indicating the last field is missing |$
|| 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
RudiC
March 24, 2014, 4:55pm
6
Try
awk 'NR==1 {split ($0, HD)}
{for (i=0; i<=NF; i++) {if($i=="") printf "row %2d, %s\n", NR, HD}}
' FS="|" file
row 2, columne 3
row 3, columne 4
row 4, columne 2
row 6, column 1