LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2014, 01:42 PM   #1
WebbSite
LQ Newbie
 
Registered: Sep 2014
Posts: 1

Rep: Reputation: Disabled
Try to evaluate input data suing awk


Hello,
I am trying to evalute input data using awk: For example
cat /etc/ssh/sshd_config | grep IgnoreRhosts | awk '{print $1,$2}' | awk '{print} END {if ($1 == "#IgnoreRhosts yes") {print "failure"}} then {if ($1 == "IgnoreRhosts yes") {print "compliant"} else {print "failure"}}' Unfortunately this does not seem to be working. Any ideas?
Thanks in Advance!
 
Old 09-25-2014, 02:06 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,797
Blog Entries: 1

Rep: Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341
Simpler to do this:
Code:
grep '^IgnoreRhosts' /etc/ssh/sshd_config > /dev/null && echo "compliant" || echo "non-compliant"
Or do you absolutely require AWK?

Last edited by szboardstretcher; 09-25-2014 at 09:25 PM.
 
Old 09-25-2014, 09:47 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,839

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
When things fail, add some diagnostics - for example try printing $1 - you might be in for a surprise.
You never need to use cat to feed awk - it reads files just fine. Likewise awk piping to another awk. Awk also has good regex support, so the grep should never be necessary.
KISS.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Extract data from a file using bash then use part of that data to rename the input fi mfarch99 Linux - Newbie 11 09-05-2014 11:51 AM
[SOLVED] AWK: how to process data multiple times in awk pix9 Programming 11 04-24-2014 08:31 AM
[SOLVED] Trying to understand how awk uses two input files bop-a-nator Linux - Newbie 9 01-10-2013 02:52 AM
Plz tell me, how to get input in awk script intikhabalam Linux - General 1 07-27-2008 08:01 AM
user input howto using awk cmontr Programming 11 09-29-2007 08:47 AM


All times are GMT -5. The time now is 04:05 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration