LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 12: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, 01:06 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
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 08:25 PM.
 
Old 09-25-2014, 08:47 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:56 AM.

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