Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, what r back refferences in SED..........i.e.,
...... Why do we use these... please explain with an example... Thanks...
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    5

    Arrow SED back references

    Hi,
    what r back refferences in SED..........i.e., \1 \2 \3......\9
    Why do we use these... please explain with an example...

    Thanks

  2. #2
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    back references are useful if you want to match a regular expresion, and replace it with different data that still contains part of what was matched.

    I.E. If I use regular expresion to match a html link
    <a href="http://www.google.com"> search engine </a>

    but I want to strip the html tags, and create a plaintext file with the URL and whatever text was linked, the 'search engine' in this example, I could
    cat somefile | sed 's!<a href="(.*)">(.*)</a>!\1::\2!g'

    and create a file with 2 field seperated by `::` with the previously mentioned data.
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...