awk AND syntax
I have a condition like this //{}
And I would like to extend the condition to the and condition. Is this syntax correct? // && // {} ... or // // {} ? No other ideas... |
I have found this to be a good reference: www.gnu.org/manual/gawk/html_node/index.html
|
I watched "Conditional Exp" and "If statement" section but no help there. "5.11 Boolean Expressions" does not fit .
|
What is wrong on this syntax?
Code:
if ($0 !~ /^[[:space:]]*title/ && |
Except the semicolon after $0 I see no issue
|
Code:
[root@localhost]# echo "Hi world" | awk 'if ($0 ~ /^[[:space:]]*title/ && $0 ~ /^[[:space:]]*hide/ && $0 ~ /^[[:space:]]*unhide/) { print $0 }' |
Never mind (Fuck it).
I have this code: Code:
block=' title sata XP (no mapping) (hd0,2) However I wanted to say: "Exclude line beginning on ^title or ^unhide or ^hide and then do {}" So it should return (hd0,20) not line #2. |
"If" statement in awk is to appear between braces {}, but if you choose to review the page I showed you, what you are looking for can be solved
without the "if()" function just include the rest: example Code:
$0 ~ /^[[:space:]]*title/ && $0 ~ /^[[:space:]]*hide/{} |
Quote:
Code:
block=' title sata XP1 (bez premapování) |
Once again the issue is you do not break anything down to see its effect. Try running the following and it should be obvious why you get your result:
Code:
block=' title sata XP1 (bez premapování) |
Sorry I don't understand you what you want I to do. I don't know what you want to say.
Edit: You think I incorrectly set separators? But there is not problem in them. I tested that the condition //{} decides what line will be processed to gensub. |
It's
Code:
(a > b && c == d) { print } Code:
if(a > b && c == d) { print } |
Have you run the above??
The output I get is: Code:
title sata XP1 (bez premapování) I will choose to look at the second record alone: Code:
0,2) 1. $0 !~ /^[[:space:]]*title/ - does this record start with any number of spaces followed by the word "title" - answer - no - therefore true 2. $0 !~ /^[[:space:]]*hide/ - does this record start with any number of spaces followed by the word "hide" - answer - no - therefore true 3. $0 !~ /^[[:space:]]*unhide/ - does this record start with any number of spaces followed by the word "unhide" - answer - no - therefore true 4. Process the following braces as all these statements are true Hence I do not believe you have tested this anywhere near as much as you should have. |
I have run your code. But I hadn't the idea. I didn't realize that the output could change. Well, next time I have to check it. Thanx
|
...........
|
All times are GMT -5. The time now is 01:35 PM. |