LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 02-18-2014, 04:14 AM   #1
raj k yadav
LQ Newbie
 
Registered: Dec 2008
Posts: 24

Rep: Reputation: 2
Filter a word : Shell Scripting


[root@daassna01vapp02 ~]# grep minlen /etc/pam.d/system-auth
password requisite pam_cracklib.so try_first_pass retry=3 minlen=8 difignore=8 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1
[root@daassna01vapp02 ~]#


How can I filter the word "minlen" and separate the number from "minlen=8" so that if condition can be applied to check the number given with "minlen=?".
 
Old 02-18-2014, 04:25 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,423

Rep: Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085
quick n dirty soln
Code:
grep minlen /etc/pam.d/system-auth |cut -d'=' -f3|cut -d' ' -f1
8
 
Old 02-18-2014, 06:04 AM   #3
raj k yadav
LQ Newbie
 
Registered: Dec 2008
Posts: 24

Original Poster
Rep: Reputation: 2
Thanks for replying chrism01, but I need to run the script for all my servers and its not necessary, everywhere the value is in the same field .
 
Old 02-18-2014, 07:11 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960
Independently from the position:
Code:
grep minlen /etc/pam.d/system-auth | awk -F= '/minlen/{print $NF}' RS=' '
Use command substitution to retrieve the number and check its value, e.g.
Code:
if [[ $(grep minlen /etc/pam.d/system-auth | awk -F= '/minlen/{print $NF}' RS=' ') -eq 8 ]]
then
  echo minlen is 8
else
  echo minlen is another number
fi
 
1 members found this post helpful.
Old 02-18-2014, 09:11 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,901

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
tut tut tut ... I would not think I would see the day when colucix would combine a needless command ... lol
Code:
awk -F= '/minlen/{print $NF}' RS=' ' /etc/pam.d/system-auth
I would also generally recommend using (()) when performing arithmetic in bash (personal preference)
 
1 members found this post helpful.
Old 02-23-2014, 12:38 PM   #6
raj k yadav
LQ Newbie
 
Registered: Dec 2008
Posts: 24

Original Poster
Rep: Reputation: 2
Thanks for your replies Colucix and Grail. Your solutions worked
 
  


Reply

Tags
awk, grep, pam, shell script


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
[SOLVED] Find/Replace shell script that replaces word with other word in text, filenames yanom Programming 8 09-12-2012 12:29 AM
Shell Scripting word scramble assistant need help with one aspect xskycamefalling Programming 3 05-10-2009 11:09 AM
newbie shell scripting need help word count air23forlife Programming 1 03-22-2007 01:12 PM
[BASH] How to filter characters away? !{param#word} {param%word}! Dark Carnival Programming 8 03-17-2005 01:49 PM


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