nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Triming a filename?

This is a discussion on Triming a filename? within the Shell scripting forums, part of the Development/Scripting category; Great website guys! Here is my problem - I've been trying to list all of the files in a bin ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 03-20-2008, 01:42 AM
Junior Member
User
 
Join Date: Mar 2008
My distro: Ubuntu (Debian)
Posts: 5
Rep Power: 0
lone_wolfy is on a distinguished road
Question Triming a filename?

Great website guys! Here is my problem - I've been trying to list all of the files in a bin directory along with their short description. Here is the command sequence I'm entering...

cd /bin
find -name '*' -exec man -f {} \;

Output are lines like this one:
./arch: nothing appropriate.

But the list doesn't contain the descriptions. I think the problem is related to the leading "./". If this is so, how can I modify the command to remove the leading "./" before it is fed to the "man -f" command? (I looked at "cut" and "awk", but they seem to be useful for data within files.)

Please help.

Thank you for a great site!
- LW
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-20-2008, 02:19 AM
Junior Member
User
 
Join Date: Mar 2008
My distro: Ubuntu (Debian)
Posts: 5
Rep Power: 0
lone_wolfy is on a distinguished road
Exclamation

I'm a little closer to a solution, but haven't yet figured out how to combine the two commands. Here is what I have so far...

echo './test' | sed -e 's/\.\///'

Output:
test

Now, if I can only properly combine this with the "man -f" in the "find" command (above).
Reply With Quote
  #3 (permalink)  
Old 03-20-2008, 02:40 AM
Junior Member
User
 
Join Date: Mar 2008
My distro: Ubuntu (Debian)
Posts: 5
Rep Power: 0
lone_wolfy is on a distinguished road
Exclamation

Still a little closer as this command lists all of the filenames that I want...

find -name '*' | sed -e 's/\.\///' | sort

But I just can't pass this output to the "man -f" command so as to list the short descriptions as well.

Argggg!!

Of course, I can simplify it further to be...

ls | sed -e 's/\.\///' | sort

To obtain the same output of filenames, but I'm still stumped as to passing the output to "man -f".
Reply With Quote
  #4 (permalink)  
Old 03-20-2008, 02:46 AM
Junior Member
User
 
Join Date: Mar 2008
My distro: Ubuntu (Debian)
Posts: 5
Rep Power: 0
lone_wolfy is on a distinguished road
Lightbulb I got it!!!!

This works well enough...

man -f `ls | sed -e 's/\.\///' | sort`

The back-ticks solved the problem!
Reply With Quote
  #5 (permalink)  
Old 03-20-2008, 10:46 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Well I'm late to party :P here is simple and clean code:
Code:
for f in $(ls /bin/*); do man -f $(basename $f); done
basename is the command you needed.
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #6 (permalink)  
Old 03-20-2008, 11:43 PM
Junior Member
User
 
Join Date: Mar 2008
My distro: Ubuntu (Debian)
Posts: 5
Rep Power: 0
lone_wolfy is on a distinguished road
Smile

Quote:
Originally Posted by rockdalinux View Post
Well I'm late to party :P here is simple and clean code:
Code:
for f in $(ls /bin/*); do man -f $(basename $f); done
basename is the command you needed.
Thanks rockdalinux! That's the ticket!
- LW
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +5.5. The time now is 03:20 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36