- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- UNIX - remembering strings from wild characters
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
10-09-2002 10:25 AM
10-09-2002 10:25 AM
Ist there a way to issue a command that will expand to the following command while using wild characters?
mv ectst_123.xxx prever_123.xxx
ex: mv ectst_*.xxx prever_(???).xxx
In other words, I'm trying to remember what the wild characters expanded to and use it in my destination filename.
Is there an alternate way?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 10:47 AM
10-09-2002 10:47 AM
Re: UNIX - remembering strings from wild characters
Read the man page carefully and I think you'll find this will do what you want.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 10:47 AM
10-09-2002 10:47 AM
Re: UNIX - remembering strings from wild characters
Here it is
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 10:54 AM
10-09-2002 10:54 AM
Solution$ for f in $(ls ectst_*)
> do
> a=$(echo $f|sed s/ectst/prever/g)
> mv $f $a
> done
Test it first with a few dummy files before you actually run it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 11:04 AM
10-09-2002 11:04 AM
Re: UNIX - remembering strings from wild characters
cd yourdirectory
ls | perl -ne 'if (/ectst_(.*?)\.xxx/) { system("mv $_ prever_\1.xxx")}'
This would require you to use regular expressions rather than filename patterns. It would give you more flexibility though...
It could be dangerous if you enter in an incorrect regular expression. It might be better to output the "mv" commands to a file for pre-inspection before executing.
ls | perl -e 'if (/ectst_(.*?)\.xxx/) { print "mv $_ prever_\1.xxx"}' >move.script.sh
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 11:05 AM
10-09-2002 11:05 AM
Re: UNIX - remembering strings from wild characters
Rodney, I haven't had time to review that tar file yet but will do... sounds interesting.
S.K., Will use your solution for now.
Take care.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 11:06 AM
10-09-2002 11:06 AM
Re: UNIX - remembering strings from wild characters
ls | perl -ne 'if (/ectst_(.*?)\.xxx/) { system("mv $_ prever_\1.xxx")}'
to
ls | perl -ne 'if (/ectst_(.*?)\.xxx/) { system("mv $_ prever_$1.xxx")}'
I forgot \1 is only effective in a s///.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 11:12 AM
10-09-2002 11:12 AM
Re: UNIX - remembering strings from wild characters
Nope. The shells just aren't that smart.
In POSIX and Korn shells, do it this way:
for file in ectst_*
do
mv $file prever_${file##*_}
done