Find the answer to your Linux question:
Results 1 to 2 of 2
Hello, I would like to change all references of $233 (any number) to ARG(233) in a text: $NUMBER -> ARG(NUMBER) How could I do this with sed or awk? Thanks ...
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    1

    How to change $NUMBER to ARG(NUMBER)

    Hello,
    I would like to change all references of $233 (any number) to ARG(233) in a text:
    $NUMBER -> ARG(NUMBER)

    How could I do this with sed or awk?

    Thanks in advance,

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    This sounds like a homework question, but I'll give you a bit of a hint.

    sed has the ability to do captures. This allows you to extract some of a match and use that text in the replacement. sed does this by using parentheses in the regular expression, and then \1, \2, \3, etc. in the replacement, where the number is the number of the capture.

    Using this, you should be able to write a sed statement that matches a statement like $N and replaces it with ARG(N).
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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