Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The or logic didn't work on bash 2

Status
Not open for further replies.

demis001

Programmer
Aug 18, 2008
94
US
These two line didn't work on my bash!

awk '{gsub(/\r/,"")}substr($0,2,15)~/\./||/^A{15}/||/^G{15}/||/^T{15}/||/^C{15}/||length($0)<14{next}1' gcb110_adaptor_removed.txt

_--------------------------------------------------------

awk 'index(substr($1, 2, 10), ".")==0||index(substr($1, 1, 15), "AAAAAAAAAAAAAAA")==0||index(substr($1, 1, 15), "GGGGGGGGGGGG")==0||index(substr($1, 1, 15), "TTTTTTTTTTTTT")==0||index(substr($1,1, 15), "CCCCCCCCCCCCC")==0||index(substr($1, 1, 14), " ")==0{print $1}' gcb110_adaptor_removed.txt

Any body speculate the reason please!

 
Can you elaboerate on "didn't work" please? Did it just do nothing? Did it give you an error?

If it just didn't produce any output, there's no way we can help you if we don't know what data you are processing and what data you expect it to produce.

Annihilannic.
 
It will not exclude the string specified by index. It print every thing. The following work with out any problem.

awk '{gsub(/\r/,"")}{print $1}' file_in.txt | awk 'index(substr($1, 2, 10), ".")==0 {print $1}'| awk 'index(substr($1, 1, 15), "AAAAAAAAAAAA")==0 {print $1}'| awk 'index(substr($1, 1, 15), "TTTTTTTTTTTT")==0 {print $1}'| awk 'index(substr($1, 1, 15), "GGGGGGGGGGGG")==0 {print $1}'| awk 'index(substr($1, 1, 15), "CCCCCCCCCCCC")==0 {print $1}'| awk 'length($1)>14{print $1}'

I want the above multiple awk statment as single awk estatment.

Dereje

"Always better to learn from friends
 
That's because you don't want OR logic, you want AND logic. The way I understand it you want to print lines that "don't contain this AND don't contain that AND don't contain something else"... right? So change the ||'s to &&'s and it should work.

Annihilannic.
 
Would you please explain to me what this statment mean litirally?

index(substr($1, 2, 10), ".")==0
 
I have looked but I don't understand why the expression evaluted to be equal to 0(==0). That is what is not clear to me. I can understand the substr part. Why we evaluta to 0

Dereje
 
What is supposed to be the return value of the index function in the man awk pages ?
 

Thanks as usual, I have looked wrong man

Dereje
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top