Check values in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check values in file
# 1  
Old 07-21-2010
Check values in file

Hi,

I have a tab delimited file in which first row is the header and others rows has the values.

Code:
A B C D
2 4 0.00 3.00
0.00 9.78 4654 898

I have to check whether all the values are zero.

Code:
A B C D
0.00 0  0.00 0.00
0.00 0.00 0 0.000

Send mail if all the values in file are zero
# 2  
Old 07-21-2010
something like this:

Code:
awk 'NR>1 {for (i=1;i<=NF;i++) if ($i!=0) a++}END {if (a>0) print a, "not all the values in file are zero"}' urfile

or 

awk 'NR>1 {for (i=1;i<=NF;i++) if ($i!=0) {print "not all the values in file are zero";exit}}' urfile

Then you can think to send it by mail or not.
# 3  
Old 07-21-2010
Code:
#!/bin/bash

exec 4<"file"
read line <&4
while read -r LINE
do
  set -- $LINE
  for((i=1;i<=$#;i++))
  do
        num=$(eval echo \$${i})
        if [[ $num > 0 ]];then
           echo "Not all values are zeros: $LINE"
           break
        fi
  done
done <&4
exec >&4-

# 4  
Old 07-21-2010
When i executed the command,

Code:
awk 'NR>1 {for (i=1;i<=NF;i++) if ($i!=0) a++}END {if (a>0) print a, "not all the values in file are zero"}' urfile

2 not all the values in file are zero

I have to skip 1st and 2nd column and 1st row from the file.
# 5  
Old 07-21-2010
Quote:
Originally Posted by sandy1028
When i executed the command,

Code:
awk 'NR>1 {for (i=1;i<=NF;i++) if ($i!=0) a++}END {if (a>0) print a, "not all the values in file are zero"}' urfile

2 not all the values in file are zero

I have to skip 1st and 2nd column and 1st row from the file.
Code:
awk 'NR>1 {for (i=3;i<=NF;i++) if ($i!=0) a++}END {if (a>0) print a, " are not Zero, \nNot all the values in file are zero"}' urfile

NR>1 : skip 1st row
i=3: skip 1st and 2nd column.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to use awk to check values and multiple

I am trying to use AWK to read a file, comma delimited, and check each field to see if it has a suffix of - (dash , minus sign) if so then I want to either move the minus sign the the beginning of the field or take the numeric portion of the field and multiply it by negative 1 to get the field... (9 Replies)
Discussion started by: ziggy6
9 Replies

2. Shell Programming and Scripting

Check if 2 input values exists in a file

I have a file number.txt.I need to get 2 inputs from the terminal like a=100 and b=200.If a and b are there in the file,then check if a < b,print "less".If a is not there in the file,print "a is missing" or if b is not there in the file,print "b is missing". number.txt: 100 200 300 (2 Replies)
Discussion started by: aneeta13
2 Replies

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

4. Red Hat

How to check for values in array?

i stored some values in array , then i traverse through the array and check for some values and if they exist then echo success. let us consider that in our array we stored values from an sql query like this #!/bin/bash declare -a arr arr=$( sqlplus -s rte/rted2@rel76d2 << EOF set... (1 Reply)
Discussion started by: ramsavi
1 Replies

5. Shell Programming and Scripting

Check to identify duplicate values at first column in csv file

Hello experts, I have a requirement where I have to implement two checks on a csv file: 1. Check to see if the value in first column is duplicate, if any value is duplicate script should exit. 2. Check to verify if the value at second column is between "yes" or "no", if it is anything else... (4 Replies)
Discussion started by: avikaljain
4 Replies

6. Shell Programming and Scripting

check for param values

I need to check for 4ht parameter values, if they are not in (17,18) in other words if they r not equal to 17 or 18 then exit. can u help pls (4 Replies)
Discussion started by: raopatwari
4 Replies

7. Solaris

check the utilization of kernel values ?

Any native Solaris commands/scripts to check the utilization of kernel tables/limits in Solaris ? (like equivalent command in HPUX is kcusage) (2 Replies)
Discussion started by: thamurali
2 Replies

8. Shell Programming and Scripting

How to check if the file contains only numeric values

How to check if the file contains only numeric values. I don't want to read entire file it eats lot of cpu Or any way which consumes less memory n cpu.. Please suggest -S (2 Replies)
Discussion started by: sunilmenhdiratt
2 Replies

9. Shell Programming and Scripting

How to check the repetition values in a file using bourne shell

Hi all, I have a scenario, like consider a file abc.txt, inside abc.txt, the contents is value1 = aaa, value2 = bbb, value3 = ccc, value1 = ddd. In this situation i need to throw an error for the repeatation of keys like "value1" is repeating twice. how to handle this using bourne... (1 Reply)
Discussion started by: Nandagopal
1 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