Finding multiple zero's in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding multiple zero's in a file
# 8  
Old 10-11-2010
Quote:
Originally Posted by frans
Anyone for the awk way ?
I do not know what the exact requirements are, perhaps this:
Code:
awk '{n=0;for(i=1;i<=NF;i++)if($i==0)n++}n>1{print "More than 1 ("n") zeroes detected: "$0}' infile

# 9  
Old 10-11-2010
Quote:
Originally Posted by frans
Anyone for the awk way ?
Code:
 awk -F " 0 " 'NF>2 {print FILENAME,"at line: ", NR,$0}' file1.txt file2.txt

# 10  
Old 10-11-2010
Quote:
Originally Posted by Scrutinizer
Code:
awk '{n=0;for(i=1;i<=NF;i++)if($i==0)n++}n>1{print "More than 1 ("n") zeroes detected: "$0}' infile

Quote:
Originally Posted by rdcwayx
Code:
 awk -F " 0 " 'NF>2 {print FILENAME,"at line: ", NR,$0}' file1.txt file2.txt

I was sure awk could do the best Smilie
# 11  
Old 10-12-2010
using loops while finding zeros

Thanxx for your replies but can someone suggest if i can use some loops so that i can echo when i encounter the zero's like:

if [ $file found zero]
then
echo "zeros found in bulk consecuively"
else
echo "everything is fine "
fi

rgds
G.C
# 12  
Old 10-12-2010
Try:
Code:
if awk '{n=0;for(i=1;i<=NF;i++)if($i==0)n++}n>1{exit 1}' infile
then
  echo "everything is fine "
else
  echo "zeros found in bulk consecutively"
fi

# 13  
Old 10-12-2010
thanks a gallon for your reply mate,
Could you also help if I want to find consecutive lines in which zeros are encountered like
0 54 55 22
0 22 55 32
0 65 97 789
0 48 99 66 41

Rgds
G.C
# 14  
Old 10-12-2010
Would that be "consecutive in the same column" in any of the columns?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding the right file with multiple sort criteria

Hello, I have files in a directory with names like, ./f0/84.40_E1200_85.39_E1300_f0_r00_1300-ON-0.25_S7A_v4_47.19.1.out.txt ./f0/84.40_E1200_85.83_E1200_f0_r00_1200-ON-0.25_S7A_v4_47.19.1.out.txt ./f0/84.60_E1100_86.45_E1100_f0_r00_1100-ON-0.25_S7A_v4_47.19.1.out.txt... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

finding matches between multiple files from different directories

Hi all... Can somebody pls help me with this... I have a directory (dir1) which has many subdirectories(vr001,vr002,vr003..) with each subdir containing similar text file(say ras.txt). I have another directory(dir2) which has again got some subdir(vr001c,vr002c,vr003c..) with each subdir... (0 Replies)
Discussion started by: bramya07
0 Replies

3. Shell Programming and Scripting

Finding strings through multiple lines

Hi, I need to search for a multiple line pattern and remove it the pattern is search for (ln number) <TABLE name=*> and if 3 lines below that the line is (ln number) </TABLE> Then remove those 4 lines. Thank you (14 Replies)
Discussion started by: legolad
14 Replies

4. UNIX for Dummies Questions & Answers

Finding nth line across multiple files

I have several files (around 50) that have the similar format. I need to extract the 5th line from every file and output that into a text file. So far, I have been able to figure out how to do it for a single file: $ awk 'NR==5' text1.txt > results.txt OR $ sed -n '5p' text1.txt > results.txt... (6 Replies)
Discussion started by: oriqin
6 Replies

5. Shell Programming and Scripting

Finding multiple column values and match in a fixed length file

Hi, I have a fixed length file where I need to verify the values of 3 different fields, where each field will have a different value. How can I do that in a single step. (6 Replies)
Discussion started by: naveen_sangam
6 Replies

6. Shell Programming and Scripting

multiple regex finding in files

Hello folks, I have a text file aa.txt that contains below text (\')|(\-\-) ((\%3D)|(=)) 20%0d% i want to search each line pattern in /opt/1.log and /opt/2.log. Can some one suggest (1 Reply)
Discussion started by: learnbash
1 Replies

7. UNIX for Dummies Questions & Answers

Finding names in multiple files - second attempt

I couldn't find the original thread that I created and since I didn't get a definitive answer, I figured I'd try again. Maybe this time I can describe what I want a little better. I've got two files, each with thousands of names all separated by new line. I want to know if 'name in file1'... (2 Replies)
Discussion started by: Rally_Point
2 Replies

8. UNIX for Dummies Questions & Answers

Finding Names in multiple files

What's the best way to see if a common name exists in two separate files? (3 Replies)
Discussion started by: Rally_Point
3 Replies

9. Shell Programming and Scripting

Expression for Finding Multiple Directories..??

I am writing a shell script to search for previous versions of an application...the application is called TAU and basically i want to search the users home directory and /Applications for any instances of a "TAU" folder.. If found i want to give the user the option to remove the old folders and if... (3 Replies)
Discussion started by: meskue
3 Replies

10. UNIX for Dummies Questions & Answers

finding multiple file types with "-o"

i was just wondering if any one had a good example of finding mutliple file types with the -o option or any other alternatives. find . \( -name "*.txt" -o -name "*.tag" \) for some reason i'm not having much luck and the man page isn't very descriptive. what i am trying to do is find all... (6 Replies)
Discussion started by: Shakey21
6 Replies
Login or Register to Ask a Question