Re: Need help with sed statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2010-05-03 at 21:37 -0600, David Bartmess wrote:
> Not sure if this is the right place, but I need help with a sed 
> replacement expression.
> 
> I'm trying to express only the filename from a filepath, i.e., 
> whoopie.txt from /opt/dev/whoopie.txt.
> 
> Basically I'm reading the files that changed into a temp file, and 
> reading each line into a variable to split out the base filename to act 
> upon.
> 
> I tried using the following, but it still gives me the entire string:
> 
> #!/bin/bash
> BASEDIR="/opt/dev";
> echo $BASEDIR | sed "s/$BASEDIR\///"
> 
> This gives me back the entire original string.
> 
> And I also tried the following sed statement:
> 
> echo $BASEDIR |  sed "s/^.*\([^/]+\)$/\1/"
> This gives me back nothing at all
> 
> Thanks for any help!

I think you want the 'basename' command:

  PATHNAME=/var/log/messages
  basename $PATHNAME

Alternately, using sed, something like:

  PATHNAME=/var/log/messages
  echo $PATHNAME|sed "s|^.*/||"

Both of these output "messages".

-Chris

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux