[ale] Shell Scripting question
nick travis
linuxnews at wormfishin.com
Wed Aug 6 14:53:45 EDT 2003
thanks for the help, what can I use to get the last three words off of a
line, instead of just the last word?
On Wed, 2003-08-06 at 13:53, Geoffrey wrote:
> nick travis wrote:
> > Here's the exact line in the file, I want to pull out the file name from
> > it.
> > VIOLATION : PAM service rlogin (/etc/pam.d/rlogin) does not have module
> > pam_shells.so for module type auth.
> > ...ACTION : Add module pam_shells.so for module type auth to PAM
> > service rlogin (/etc/pam.d/rlogin).
> > Example: auth required /lib/security/pam_shells.so
> >
> > there will be several violations like this in the file, but the file
> > name will start at a different location each time. since the violation
> > will be in a different file.
>
> Well, that message contains three different references to file names,
> but you can get to all of them with the right tool. If for example you
> want the name that's contained between the parans, you can use awk:
>
> awk -F '[()]' '{print $2}' intputfile
>
> The above will retreive the first occurance of /etc/pam.d/rlogin.
> Basically you're telling awk that there are two field separators and
> they are the parans. Therefore, the file name would be the second field.
>
> Same solution would apply for the second /etc/pamd./rlogin entry, you'd
> just have to adjust the '$2' appropriately.
>
> The last file reference (/lib/security/pam_shells.so) can be had by the
> previous posted solution:
>
> awk '{print $NF}' inputfile
>
>
> NF in awk is the number of fields, therefore $NF is the last field value.
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list