Raynon
August 22, 2007, 8:50pm
1
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
Ygor
August 22, 2007, 9:23pm
2
Try...
awk '{if ($1>1) print $0; else print "No Re-occurrence"}' file1
awk '$1>1?1:$0="No occurence"' file
output:
# ./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.
Raynon
August 23, 2007, 1:26am
4
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
If you do not want the lines with first column =1 then just remove the else part of the syntaxes recomended above.
Thanks
namish
aigles
August 23, 2007, 4:27am
6
Try this :
awk '$1>1 { print; c++ } END { if (c==0) print "No occurrence" }' file
Jean-Pierre.
Raynon
September 5, 2007, 1:39am
7
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
Raynon
September 5, 2007, 6:38pm
8
Can any experts give me some advice on this ?