- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: capturing directories of files
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
тАО12-27-2004 05:17 PM
тАО12-27-2004 05:17 PM
If I have say :
DIR1/DIR2/DIR3/a.txt
DIR1/DIR2/b.txt
DIR1/DIR2/c.txt
DIR1/DIR2/DIR3/DIR4/d.txt
DIR1/DIR2/DIR3/e.txt
...
If the list goes on and on, how do i write a script to create a list of Directories where the files belong to..
i.e.
DIR1/DIR2/DIR3/
DIR1/DIR2/
DIR1/DIR2/
DIR1/DIR2/DIR3/DIR4/
DIR1/DIR2/DIR3/
any suggestion?
thanks!
Solved! Go to Solution.
- Tags:
- dirname
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-27-2004 05:39 PM
тАО12-27-2004 05:39 PM
Re: capturing directories of files
have a look at "dirname". "dirname" and "basename" are used to extract directory name and file name from a full path.
regards,
Thierry Poels.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-27-2004 05:45 PM
тАО12-27-2004 05:45 PM
Re: capturing directories of files
sed "s/[^\/]*$//" yourfile
regards,
Thierry Poels.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-27-2004 06:18 PM
тАО12-27-2004 06:18 PM
Re: capturing directories of files
The sed command was really very helpful, can u roughly explain how the command works?
more importantly, what if I want to output:
DIR1/DIR2/DIR3
DIR1/DIR2
DIR1/DIR2
DIR1/DIR2/DIR3/DIR4
DIR1/DIR2/DIR3
i.e. less the extra "/" at the back?
really hope u can help
THank u!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-27-2004 06:51 PM
тАО12-27-2004 06:51 PM
Solutionsed "s/\/[^\/]*$//" yourfile
(just added another (escaped) / )
or
sed "s;/[^/]*$;;" yourfile
(with a different delimeter)
[^\/] = any character different from "/"
[^\/]* = contiguous group of characters different from "/"
[^\/]*$ = contiguous group of characters different from "/" at the end of the line
and simply replace it with an empty string.
See "man sed" for more info.
regards,
Thierry Poels.
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-27-2004 07:05 PM
тАО12-27-2004 07:05 PM
Re: capturing directories of files
Many thanks!!