Given a file input.txt
with contents:
xyMnZnMs76XHgsWJ
size: YN3hxFqFeUxXUMrQ
USPqYEnbquwFhUW7
vhJJduHZu25qHzTw
size: JaTDhQYQtLRWBLjj
uE5HGDAZN6DHU73Q
QxVPfQQaKTgR9LXQ
grnsm8bwSz5fJbQS size:
7CcuZxCHSJYhcdqg
ZuWadAaLWFwDwj5Z
how to use if (condition) {...} else {...}
?
I tried to use:
awk -F ':' '
IF ($1 ~ /size/) {
print "match: "$0;
} ELSE {
print "non-match: "$0;
}' input.txt
but all lines are matched (even ones without $1
containing "size"
):
match: xyMnZnMs76XHgsWJ
match: size: YN3hxFqFeUxXUMrQ
match: USPqYEnbquwFhUW7
match: vhJJduHZu25qHzTw
match: size: JaTDhQYQtLRWBLjj
match: uE5HGDAZN6DHU73Q
match: QxVPfQQaKTgR9LXQ
match: grnsm8bwSz5fJbQS size:
match: 7CcuZxCHSJYhcdqg
match: ZuWadAaLWFwDwj5Z
I expect the output to be:
non-match: xyMnZnMs76XHgsWJ
match: size: YN3hxFqFeUxXUMrQ
non-match: USPqYEnbquwFhUW7
non-match: vhJJduHZu25qHzTw
match: size: JaTDhQYQtLRWBLjj
non-match: uE5HGDAZN6DHU73Q
non-match: QxVPfQQaKTgR9LXQ
non-match: grnsm8bwSz5fJbQS size:
non-match: 7CcuZxCHSJYhcdqg
non-match: ZuWadAaLWFwDwj5Z