We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to remove pathname from a filename

ambuli
ambuli asked
on
Medium Priority
480 Views
Last Modified: 2012-05-11
Hi Experts,

I want to remove the pathname from a filename.

./path/name/file.txt
I want to change this to just file.txt ( everything upto the last / should be removed)

How can I do it.

Thanks,
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Thanks you
CERTIFIED EXPERT

Commented:
Sorry, remove the last "/", so the substitution line reads:
    ($filename = $pathname) =~ s|.*/||;

Author

Commented:
Hi tel2,

I am getting syntax errors.

syntax error at searchLogs.pl line 51, near "/;"
CERTIFIED EXPERT

Commented:
I know. ambuli.  Did you read my 2nd post, above?

Author

Commented:
Sorry, I did not check that before.  Yes, it is working fine.  Thank you.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.