LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-01-2014, 08:42 AM   #1
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Mint, Ubuntu server, FreeBSD, Android
Posts: 362

Rep: Reputation: 32
awk filter & print


Hello,

I am doing something that must be pretty basic in awk: I would like to select all lines from a file in which the second field is a given number, ie 30 (the day of the month):
Code:
$ cat /var/log/messages | awk  '{$2 ~/30/; print $0}'
This doesn't work. What am I missing?
 
Old 12-01-2014, 08:52 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
What are you missing? ..... You need to learn the usage/syntax of awk:
awk '$2 == 30' /var/log/messages
(yes, cat is not required at all)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Filter a text with awk, grep or sed Tchiarot Programming 12 02-12-2014 04:06 PM
[SOLVED] awk print dos not print text value jozelo Linux - Newbie 2 10-23-2013 04:37 AM
[SOLVED] Awk question - Search, print & replace strings shivaa Linux - Newbie 6 12-06-2012 01:03 PM
[SOLVED] awk script to filter and delete crxlurp Linux - Newbie 6 07-05-2011 01:33 PM
Using sed or awk to filter a file mitchell2345 Linux - Software 3 04-10-2009 10:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration