The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
filtering the logs prvnrk Shell Programming and Scripting 5 04-08-2008 06:57 PM
awk and sed filtering invinzin21 Shell Programming and Scripting 2 01-10-2008 11:56 PM
Filtering Data bobo UNIX for Dummies Questions & Answers 2 09-19-2007 12:06 PM
awk filtering ? varungupta UNIX for Advanced & Expert Users 4 09-16-2007 11:55 PM
Filtering out data ... videsh77 UNIX for Dummies Questions & Answers 1 12-29-2004 12:59 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-22-2007
Registered User
 

Join Date: Sep 2006
Location: Sg
Posts: 316
Stumble this Post!
Filtering Data

Hi All,

I have the below input and expected ouput. I need a code which can scan through this input file and if the number in column1 is more than 1 , it will print out the whole line, else it will output "No Re-occurrence". Can anybody help ?

Input:

1 vvvvv 20 7 7 23 0 64
6 zzzzzz 11 5 5 13 0 1
1 uuuuu 17 0 0 24 0 146
5 qqqqq 7 3 3 11 0 199
1 ggggg 11 5 5 13 0 13
1 yyyyy 13 7 7 31 0 252


Expected Output:

6 zzzzzz 11 5 5 13 0 1
5 qqqqq 7 3 3 11 0 199
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-22-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Stumble this Post!
Try...
Code:
awk '{if ($1>1) print $0; else print "No Re-occurrence"}' file1
Reply With Quote
  #3 (permalink)  
Old 08-22-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,542
Stumble this Post!
Code:
awk '$1>1?1:$0="No occurence"' file
output:
Code:
# ./test.sh
No occurence
6 zzzzzz 11 5 5 13 0 1
No occurence
5 qqqqq 7 3 3 11 0 199
No occurence
No occurence
by the way, try to put in some effort next time.
Reply With Quote
  #4 (permalink)  
Old 08-22-2007
Registered User
 

Join Date: Sep 2006
Location: Sg
Posts: 316
Stumble this Post!
Hi Ghostdog,

I only want the the below to surface column1 more than 1.


6 zzzzzz 11 5 5 13 0 1
5 qqqqq 7 3 3 11 0 199


If column1 does not contain 1 then output "No occurence"

eg
Input:
1 vvvvv 20 7 7 23 0 64
1 uuuuu 17 0 0 24 0 146
1 ggggg 11 5 5 13 0 13
1 yyyyy 13 7 7 31 0 252


Output:
No occurrence
Reply With Quote
  #5 (permalink)  
Old 08-22-2007
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 285
Stumble this Post!
If you do not want the lines with first column =1 then just remove the else part of the syntaxes recomended above.

Thanks
namish
Reply With Quote
  #6 (permalink)  
Old 08-23-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Stumble this Post!
Try this :
Code:
awk '$1>1 { print; c++ } END { if (c==0) print "No occurrence" }' file
Jean-Pierre.
Reply With Quote
  #7 (permalink)  
Old 09-04-2007
Registered User
 

Join Date: Sep 2006
Location: Sg
Posts: 316
Stumble this Post!
Thnks Jean it works!!

However, how can i modify the code such that when 2 or more terms are repeated consecutively, it will output the the repeating term, else echo "No consecutive repeating term ?

Input:
vvvvv 20 7 7 23 0 64
uuuuu 17 0 0 24 0 146
uuuuu 17 0 0 24 0 146
uuuuu 17 0 0 24 0 146
ggggg 11 5 5 13 0 13
yyyyy 13 7 7 31 0 252
ggggg 11 5 5 13 0 13


Expected Output:
Consecutive Repeating term = uuuuu 17 0 0 24 0 146

Last edited by Raynon; 09-04-2007 at 10:56 PM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0