- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- perl substitution question
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
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
тАО07-08-2004 01:29 AM
тАО07-08-2004 01:29 AM
I have a file as follows :-
juve00_04070706
and require to substitute using perl syntax =~s/ etc everything after the _ to become :-
juve00_********
Can anyone help ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2004 02:56 AM
тАО07-08-2004 02:56 AM
Re: perl substitution question
echo test_change | perl -p -e 's/_.*/done/'
which will change test_change to testdone.
If you are just trying to change a file name while running ksh, you do not need to use perl, you can use this:
fn=test_change
newfn=${fn%_*}done
echo $newfn
The "%" tells ksh to remove the small right pattern that matches "_*", where "*" is a wild card that matches all characters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2004 03:01 AM
тАО07-08-2004 03:01 AM
Re: perl substitution question
This is embedded within a perl script, so I am looking for something like :-
filename=juve00_04050607
$filename2=~s/_*/********/ (but this does not work)
I need to substitute everything after the underscore to be *
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2004 03:12 AM
тАО07-08-2004 03:12 AM
Re: perl substitution question
echo "juve00_04050607"|awk -F "_" '{print $1,"_********"}'
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2004 03:31 AM
тАО07-08-2004 03:31 AM
Re: perl substitution question
It must be perl - some sort of substitution or translation, i think
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2004 03:40 AM
тАО07-08-2004 03:40 AM
SolutionTo indicate a series of anything you use .* in perl, not just the *
So in it's simplest form your problem can be solved by:
$filename=shift; # take from command line
$filename=~ s/_.*$/_******/;
print "$filename\n";
But what is your exact problem definition?
The last underscore?
Replace the tail wih a fixed series of stars, or wiht as many stars as there where characters? numbers only?
Here is a more elaborate solution replacing the chracters following the last understcore with as many stars:
$filename=shift;
if ($filename =~ /(.*_)(.*)$/) {
$head = $1;
$tail = $2;
$tail =~ s/./*/g;
$filename = $head . $tail;
}
print "$filename\n";
You may want to read up more on regular expression, the 'tr' function, the 's' functions and perhpas also check out 'rindex' and 'substr'.
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2004 03:47 AM
тАО07-08-2004 03:47 AM