Operating System - HP-UX
1748181 Members
4120 Online
108759 Solutions
New Discussion юеВ

Re: Need Only file names from the ll Output

 
SOLVED
Go to solution
Vidhya B
Frequent Advisor

Need Only file names from the ll Output

Hi,

I am working on a script. I need to open files whose filenames has the word Password_Expiry one by one in a particular path.

server:\>ll | grep -i Password_Expiry
-rw------- 1 glance users 22 Apr 28 11:26 Password_Expiry_A
-rw------- 1 glance users 22 Apr 28 11:26 Password_Expiry_B


Now I need to login to each file one by one. How will I be able to do it?

Is there any command which gives me output like below?

Password_Expiry_A
Password_Expiry_B


Kindly help.
6 REPLIES 6
g3jza
Esteemed Contributor
Solution

Re: Need Only file names from the ll Output

Hi,

ll|grep -i Password_Expiry | awk '{ print $9 }'

Bill Hassell
Honored Contributor

Re: Need Only file names from the ll Output

A bit simpler:

ls -1 | grep Password_Expiry

Or with awk:

ll | awk '/Password_Expiry/{print NF}'


Bill Hassell, sysadmin
Steven Schweda
Honored Contributor

Re: Need Only file names from the ll Output

There's something to be said for "find" with
"-name 'Password_Expiry*'". As always, there
are details, but it seems a shame to get all
that "ls -l" info and then ignore it.
James R. Ferguson
Acclaimed Contributor

Re: Need Only file names from the ll Output

Hi:

I must add that Steven's point(er) is well-taken.

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Need Only file names from the ll Output

>Steven: it seems a shame to get all that "ls -l" info and then ignore it.

Of course "ls *Password_Expiry_*" or "ls | grep -i Password_Expiry" work too.
Also the shell: echo Password_Expiry_*
(With suitable checks for no matches.)
Manix
Honored Contributor

Re: Need Only file names from the ll Output

find /_path -name "Password_Ex*" -exec -xdev
ll {}\; | awk '{print $6} | more

Thanks
Manix
HP-UX been always lovable - Mani Kalra