Re: awk fields
- From: Janis Papanagnou <janis_papanagnou@xxxxxxxxxxx>
- Date: Wed, 01 Sep 2010 23:32:37 +0300
Am 30.08.2010 19:06, schrieb Ed Morton:
On 8/30/2010 10:59 AM, Seebs wrote:On 2010-08-30, contracer<contracer11@xxxxxxxxx> wrote:Hi,
How verify with awk if field 15 haves number 8 ?
Command below doesn´t work...
Please read:
http://catb.org/esr/faqs/smart-questions.html
In particular, you have not told us HOW it doesn't work. Are you getting
an error message? Are you getting unexpected output? Are you getting
output
you didn't expect?
cat tapes.lis | awk ' { if ($15=8) { print $0 }}'
This seems gratuitously complicated. Try:
awk '$15 = 8'
Unlike shell, "=" is an assignment, "==" is a test:
Sorry to nit-pick. As in shell, "=" is an assignment.
"==" is also the equality test in modern shells, in
addition to the old "=", which may even be deprecated
(as in Kornshell).
Janis
awk '$15 == 8' tapes.lis
Regards,
Ed.
All awk rules can be preceded by a condition, which simplifies your life
a bit here. And if you don't specify a rule, it is implicitly '{print
$0}',
so you don't need the rule.
That said!
My psychic powers tell me that the problem is you're not seeing output
you expect, and that tapes.lis is a tab-delimited file. What you aren't
taking into account is that awk uses *any* whitespace to separate fields,
and you have some tapes which have fields which contain spaces,
meaning that
the 15th tab-separated field isn't really the 15th field of the line.
Try:
awk -F ' ' '$15 = 8'
(where the space between the first two ''s is a tab).
If that's not it, well. The notorious unreliability of psychic powers
is why you should explain your question better; again, see the link.
-s
.
- Follow-Ups:
- Re: awk fields
- From: Aragorn
- Re: awk fields
- Prev by Date: Re: Weirdest shell behavior ever...
- Next by Date: Re: Weirdest shell behavior ever...
- Previous by thread: Weirdest shell behavior ever...
- Next by thread: Re: awk fields
- Index(es):
Relevant Pages
|