Results 1 to 4 of 4

Thread: SED from a shell script - driving me up the wall!!!

  1. #1
    Join Date
    Dec 2012
    Beans
    74

    SED from a shell script - driving me up the wall!!!

    why does this work

    sed -e 's/.*Jun 19//' myfile

    And this not

    mmm=Jun
    dd=19
    sed -e 's/.*$mmm $dd//' myfile


    both being ran from a shell scrip, not CLI

    myfile:
    < Jun 19 00:00:00 some data


    I've tried quotes round it, no joy, i'm using *. as i'd like to lose the < too.

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: SED from a shell script - driving me up the wall!!!

    It's nothing to do with sed specifically - single quotes prevent expansion of shell variables, try double quotes instead

    Code:
    sed -e "s/.*$mmm $dd//" myfile
    Be aware that this *can* allow the shell to expand things you *don't* want it to in certain circumstances

  3. #3
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: SED from a shell script - driving me up the wall!!!

    Because you are using single quotes. That tells bash to treat the quoted string as a literal. Try using double quotes (") instead. Then bash will replace the variables with their values.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  4. #4
    Join Date
    Dec 2012
    Beans
    74

    Re: SED from a shell script - driving me up the wall!!!

    ahh, thank-you very much - you learn something new every day..

Bookmarks

Posting Permissions

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