Re: sed substitution that contains forward slash

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

 



Craig White wrote:
> subtitle...fun with sed
>
> I have a list of changes to make to a file...
>
> dc              rc
> -------------   -------
> 15T6145V        DELETED
> NATL19502       DELETED
> Q10MR11/FL12V   DELETED
> Q1500T3/CL120   DELETED
>
> and things work until I get to the 3rd item which has a forward
> slash and it fails to substitute with commands like below...
>
> sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv
> and
> sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv
>
> The latter producing error on screen...
> sed: -e expression #1, char 17: unknown option to `s'
>
> While the former simply doesn't complain but doesn't make the change
> either.

Hmm, it should work using a delimeter other than '/' or escaping the
'/'.  Escaping the '/' is a bit more of a pain than just changing
delimeters, as long as you know that whatever delimeter you pick won't
be in the strings you are substituting.

It seems to work for me:

$ dc="Q10MR11/FL12V"; rc=DELETED; echo "dc=${dc}"; echo "rc=${rc}"; \
  echo "This is some Q10MR11/FL12V text." | sed "s%${dc}%${rc}%g"
dc=Q10MR11/FL12V
rc=DELETED
This is some DELETED text.

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is dangerous to be sincere unless you are also stupid.
    -- George Bernard Shaw (1856-1950)

Attachment: pgpSTj54Jd2Yg.pgp
Description: PGP signature

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[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