- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Regarding string manipulation and ls in unix s...
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
Forums
Discussions
Discussions
Discussions
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
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
08-13-2006 06:52 PM
08-13-2006 06:52 PM
1. str1=topasa1
i want to store it in another string str2 as
str2=asa1
How do i do it in unix shell script
2. when i do a ls -ltr
ls -ltr
total 4
-rw-r--r-- 1 scc scc 8 Aug 14 00:46 test1
-rw-r--r-- 1 scc scc 17 Aug 14 00:47 test2
i want the latest file of test* to be stored in a string x1 how do i do it?
x1=ls -ltr test* |......
or
x1 = ls -lt test* |....
how do i get the latest file test2 into x1
i need to get the output as x1=test2
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2006 07:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2006 08:52 PM
08-13-2006 08:52 PM
Re: Regarding string manipulation and ls in unix shell script
> ls -tr /home/users/fcc/prodfiles/test* | tail -1
/home/users/fcc/prodfiles/test2
I want the variable x2 to have test2 only
x2=`ls -tr /home/users/fcc/prodfiles/test* | tail -1`|.....
what do i need to do for this one. Also the directory name,path might change. i want to filter the content after final "/" to get the file name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2006 09:07 PM
08-13-2006 09:07 PM
Re: Regarding string manipulation and ls in unix shell script
please see:
man basename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2006 11:06 PM
08-13-2006 11:06 PM
Re: Regarding string manipulation and ls in unix shell script
>ls -tr /home/users/scc/prodfiles/test* | tail -1
/home/users/fcc/prodfiles/test2
I did the below one but i didn't get the output.
ls -tr /home/users/fcc/prodfiles/test* |tail -1 | basename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2006 11:48 PM
08-13-2006 11:48 PM
Re: Regarding string manipulation and ls in unix shell script
${x1##*/}
that will drop off the path part of the variable. Useful if you want to preserve the path for some reason.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 12:02 AM
08-14-2006 12:02 AM
Re: Regarding string manipulation and ls in unix shell script
x1=`ls -tr /home/users/fcc/prodfiles/test* |tail -1`
x1=`basename $x1`
Also could you review your current threads after reading
http://forums1.itrc.hp.com/service/forums/helptips.do?#28
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 12:11 AM
08-14-2006 12:11 AM
Re: Regarding string manipulation and ls in unix shell script
# x1=$(basename $(ls -1t /home/users/scc/prodfiles/test* | head -n 1))
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 01:19 AM
08-15-2006 01:19 AM
Re: Regarding string manipulation and ls in unix shell script
$ str1=topasa1
$ str2=${str1#???}
Then:
$ print str2
to see the result
In this case each "?" removes antoher character from the left. To remove from the right, user "%".
Will
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 01:22 AM
08-15-2006 01:22 AM
Re: Regarding string manipulation and ls in unix shell script
$ print $str2
Sorry,
Will
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2006 07:41 PM
09-06-2006 07:41 PM