- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Query on Small sed output + ls-ltr
Operating System - HP-UX
1752565
Members
5329
Online
108788
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
тАО05-07-2008 07:40 PM
тАО05-07-2008 07:40 PM
Query on Small sed output + ls-ltr
Hello,
I have 2 questions-
1) What is the signifiance of sed part in below command:
find $glob_path/*.txt -type f -print 2>/dev/null | sed -n '/'$CTY'invdet[0-9][0-9]*.txt$/p'
2) IF I want to have name of just the latest file generated using ls -ltr, How do i get that?
Thank you!
I have 2 questions-
1) What is the signifiance of sed part in below command:
find $glob_path/*.txt -type f -print 2>/dev/null | sed -n '/'$CTY'invdet[0-9][0-9]*.txt$/p'
2) IF I want to have name of just the latest file generated using ls -ltr, How do i get that?
Thank you!
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-07-2008 08:13 PM
тАО05-07-2008 08:13 PM
Re: Query on Small sed output + ls-ltr
> 1) What is the signifiance of sed part in
> below command:
It passes only the lines which match that
pattern. "man sed".
> [...] How do i get that?
One way:
ls -ltr | tail -1
> find $glob_path/*.txt [...]
Do you really want to let the shell expand
that wildcard "*.txt"?
> sed -n '/'$CTY'invdet[0-9][0-9]*.txt$/p'
If you really want names like "xxx.txt", and
not names like "xxxxtxt", then you might wish
to escape that last "." in the "sed" pattern:
sed -n '/'$CTY'invdet[0-9][0-9]*\.txt$/p'
For example:
td176> ls -lrt | sed -n '/tr.*2.cpp/p'
-rw-rw-rw- 1 antinode 513 207 May 6 09:25 trail2.cpp
-rw-rw-rw- 1 antinode 513 5 May 8 00:05 trail2xcpp
td176> ls -lrt | sed -n '/tr.*2\.cpp/p'
-rw-rw-rw- 1 antinode 513 207 May 6 09:25 trail2.cpp
In a "sed" expression, an unescaped "."
matches _any_ character, not only ".".
> below command:
It passes only the lines which match that
pattern. "man sed".
> [...] How do i get that?
One way:
ls -ltr | tail -1
> find $glob_path/*.txt [...]
Do you really want to let the shell expand
that wildcard "*.txt"?
> sed -n '/'$CTY'invdet[0-9][0-9]*.txt$/p'
If you really want names like "xxx.txt", and
not names like "xxxxtxt", then you might wish
to escape that last "." in the "sed" pattern:
sed -n '/'$CTY'invdet[0-9][0-9]*\.txt$/p'
For example:
td176> ls -lrt | sed -n '/tr.*2.cpp/p'
-rw-rw-rw- 1 antinode 513 207 May 6 09:25 trail2.cpp
-rw-rw-rw- 1 antinode 513 5 May 8 00:05 trail2xcpp
td176> ls -lrt | sed -n '/tr.*2\.cpp/p'
-rw-rw-rw- 1 antinode 513 207 May 6 09:25 trail2.cpp
In a "sed" expression, an unescaped "."
matches _any_ character, not only ".".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-07-2008 09:18 PM
тАО05-07-2008 09:18 PM
Re: Query on Small sed output + ls-ltr
>1) What is the significance of sed part in below command:
find $glob_path/*.txt -type f -print 2>/dev/null | sed -n '/'$CTY'invdet[0-9][0-9]*.txt$/p'
If you want to make it clearer, you could have used grep instead:
... | grep $CTY'invdet[0-9][0-9]*.txt$'
And if you want a literal ".", you escape it the same way Steven said.
find $glob_path/*.txt -type f -print 2>/dev/null | sed -n '/'$CTY'invdet[0-9][0-9]*.txt$/p'
If you want to make it clearer, you could have used grep instead:
... | grep $CTY'invdet[0-9][0-9]*.txt$'
And if you want a literal ".", you escape it the same way Steven said.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2008 05:03 AM
тАО05-14-2008 05:03 AM
Re: Query on Small sed output + ls-ltr
>2) IF I want to have name of just the latest file generated using ls -ltr, How do i get that
If you want ONLY the file name using ls -ltr:
ls -ltr|tail -1 |awk '{print $9}'
or
if you want to use ls:
ls -rt1|tail -1
Rgds.
If you want ONLY the file name using ls -ltr:
ls -ltr|tail -1 |awk '{print $9}'
or
if you want to use ls:
ls -rt1|tail -1
Rgds.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP