Quote:
Originally Posted by grail
Well I think for the two scenario that ntubski's is the winner, but happy to throw hat in for or more part:
Code:
awk 'BEGIN{patterns="aunque tengo";split(patterns,array)}{for(x in array)if($0 ~ array[x])i++;if(i < 3)print;i=0}' input_file > output_file
|
I think the only problem with your code is that the number of rgexs to look for is hard coded into the "if(i < 3)" expression.
I am thinking of adding a variable having the array length stored in it, and use it in the conditional.
But anyway these are the codes that make just the right thing
Code:
#!/bin/bash
sed '/aunque/{/me/{/daņo/d}}' $1 > output_file
sed '/aunque.*me.*daņo/d' $1 > output_file2
awk 'BEGIN{patterns="aunque me daņo";split(patterns,array)}{for(x in array)if($0 ~ array[x])i++;if(i < 3)print;i=0}' $1 > output_file3
max_matches=1 #max number of pattern matches allowed
patterns=('aunque' 'me' 'daņo') #the patterns to match (you can use as many as you want)
file="$1"
counts="$( eval echo -n {1..$(($max_matches+1))} | tr ' ' '|' )"
{ for pattern in "${patterns[@]}"; do
egrep -n "$pattern" "$file"
done; grep -n '' "$file"; } | sort -n | uniq -c | egrep "^ *($counts) " | sed -r 's/^[^:]+://'
exit
Can awk edit in place, like the -i option in sed?
p.s.Now i looked for sed -r option in google, and i got this:
-r, --regexp-extended
use extended regular expressions in the script.
And what the heck are those, expanded regexps?
Somebody, some light, which are normal and which advanced, regexp?