Microsoft
Software
Hardware
Network
Question : Sed, Awk or Bash - Pull text out of a line
I am trying to parse a PAM file to get a value for a variable. I am having some problems pulling some information from a line in the file. It is fairly straight forward to get the correct line from the file with grep -Ei or sed or even awk. The problem I am having is getting a certain bit of information from the line. The line is something like this:
account required /lib/security/$ISA/pam_tal
ly.so per_user deny=3 onerr=fail no_magic_root reset. I am able to get the line I need by doing something like this:
sed -n '/^account.*pam_tally.*den
y/p' /etc/pam.d/system-auth - obviously there are a number of ways to do this (grep & awk also). What I need is a way to get the "5" in the "deny=5" section of the line. If the deny=5 was guaranteed to be in the same place (same field number) it would be pretty easy, but it is not. I could use cut or awk etc. Is there good way to get this data ( the 5 ) without knowing were in the line it may be. I need to use sed, awk, or bash type commands.
Thank You
Answer : Sed, Awk or Bash - Pull text out of a line
perl -ne 'print "$1\n" if /^account.*pam_tally.*deny
=(\d+)/' /etc/pam.d/system-auth
awk '/^account.*pam_tally.*den
y/{sub(/.*
deny=/,"")
;sub(/[^0-
9].*/,"");
print}' /etc/pam.d/system-auth
Random Solutions
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator
STOP Error codes 0x00000024 & 0x0000007B
NT workstation cannot connect to Winfax Server on 2000 Pro
Exchange services need to be restarted after full backup exec job
Dell Precision T3400 Stuck at Starting PC-Dos on ghost boot disk
Challenging Trojan! - downloader.delf.2.BC
Calendar - 15 minute intervals
Sum based on condition
OWA in Exchange 2K3 & W2K3, SSL Certificate, Inheritance overrides
Adobe 9 send doc as mail