Skip to content
Snippets Groups Projects

Replace @-delimited string with expanded environment variable

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Marcel Loose

    The perl one-liner below will replace every occurrence of @some_string@ with the value of the environment variable some_string (i.e. what you get when you echo ${some_string}). For example, suppose you've got a file that contains the following text:

    I like to eat @FRUIT@ @WHEN@.

    If you run the one-liner on this file, with the environment variables FRUIT=apples and WHEN=daily, then the output will be:

    I like to eat apples daily.
    snippetfile1.txt 35 B
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment