- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to parse out fields using awk?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 01:47 AM
тАО06-14-2004 01:47 AM
I have a shell script that finds and lists the full path to a file. (The filename always changes) I need to parse out all fields including the forward slashes because I only need the filename at the end of the path.
ex. /var/opt/filename
What would be the best way to do this?
10 points ot any good answer.
TIA, Gino
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 01:52 AM
- Tags:
- basename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 01:53 AM
тАО06-14-2004 01:53 AM
Re: How to parse out fields using awk?
Are you looking for the "basename" command?
#man basename
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 01:53 AM
тАО06-14-2004 01:53 AM
Re: How to parse out fields using awk?
Firstly "basename /var/opt/filename" will give you "filename". However, I don't understand why you would need to do this because presumably you already had the filename in order to find it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 01:55 AM
тАО06-14-2004 01:55 AM
Re: How to parse out fields using awk?
Mark: I'm using the 'find' command to locate the file so it returns the fullpath.
All: The 'basename' command looks like the solution to me.
10 points to any good answer.
TIA, Gino
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 01:58 AM
тАО06-14-2004 01:58 AM
Re: How to parse out fields using awk?
# filevar=/var/adm/syslog/syslog.log
# basename $filevar
syslog.log
# dirname $filevar
/var/adm/syslog
#
live free or die
harry
- Tags:
- dirname
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 02:02 AM
тАО06-14-2004 02:02 AM
Re: How to parse out fields using awk?
find / -name filename -exec basename {} \;
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 02:08 AM
тАО06-14-2004 02:08 AM
Re: How to parse out fields using awk?
basename $FILE
and
dirname $FILE
are the best solution, but if you like awk:
PATH=$(echo $FILE|awk -F/ '{$NF="";print}' | sed 's? ?/?g'
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 02:08 AM
тАО06-14-2004 02:08 AM
Re: How to parse out fields using awk?
sorry, but the find command doens't already show the fullpath?
For example:
filename under /pippo/pluto
# find / -name filename
/pippo/pluto/filename
It returns fullpath then I don't understand your problem.
Otherwise I hope that other ITRC guys will help you better than me.
Best regards,
Ettore
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2004 02:12 AM
тАО06-14-2004 02:12 AM
Re: How to parse out fields using awk?
Fabio: When I run the find command while searching for a particular file it returns the full path with the file itself.
I just need the file name by itself, I want to remove the rest of the string (which includes the full path).
10 points to any good answer.
TIA, Gino