Find the answer to your Linux question:
Results 1 to 8 of 8
Hi Because my GR_RESOURCE_DIR variable has - character in it the sed doesn't work. Could you please advise ? [root@skynet conf]# cat globalrelay.ini [Basic Configuration] ResourceDIR=/app-nfs/meta/relay [root@skynet bianca]# cat xac.sh ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    30

    Sed a variable which has - character in it

    Hi

    Because my GR_RESOURCE_DIR variable has - character in it the sed doesn't work. Could you please advise ?

    [root@skynet conf]# cat globalrelay.ini
    [Basic Configuration]
    ResourceDIR=/app-nfs/meta/relay

    [root@skynet bianca]# cat xac.sh
    #!/bin/bash

    GR_RESOURCE_DIR=new-app

    sed -e "s-\(^ResourceDIR=\)\([^#]*\)-\1${GR_RESOURCE_DIR}-" aaaa > bbbb

    [root@skynet bianca]# ./xac.sh
    sed: -e expression #1, char 36: unknown option to `s'

    Thanks,
    Bianca

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    # GR_RESOURCE_DIR=new-app
    # awk -v gr=$GR_RESOURCE_DIR '{sub("ResourceDIR",gr)}1' file.ini

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    30
    This command replace ResourceDIR with the variable not what comes after ResourceDIR=

    And I need sed because I have multiple variables.

    If the variable doesn't have - character the script works

    Thanks,
    Bianca

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    # awk -F"=" -v gr=$GR_RESOURCE_DIR '/ResourceDIR/{$2=gr;}1' OFS="=" file
    ResourceDIR=new-app

  5. #5
    Just Joined!
    Join Date
    Mar 2008
    Posts
    30
    Quote Originally Posted by ghostdog74 View Post
    Code:
    # awk -F"=" -v gr=$GR_RESOURCE_DIR '/ResourceDIR/{$2=gr;}1' OFS="=" file
    ResourceDIR=new-app
    Thanks a lot. It works for this parameter.
    But also I have another type of parameter in the config file:

    MountFolderLive=/live/, /xac-nfs/meta/live
    MountFolderPlaylist=/playlist/, /xac-nfs/meta/playlist/blah

    And here the awk example doesn't work if I do like this
    awk -F"=" -v gr=$GS_MOUNT_FOLDER_META '/MountFolderLive=/live//{$2,gr;}1' OFS="=" file
    awk -F"=" -v gr=$GS_MOUNT_FOLDER_PLAYLIST '/MountFolderPlaylist=/playlist//{$2,gr;}1' OFS="=" file

    awk: cmd. line:1: /MountFolderLive=/live//{$2,gr;}1
    awk: cmd. line:1: .............................. ^ syntax error
    awk: cmd. line:1: /MountFolderLive=/live/{$2,gr;}1
    awk: cmd. line:1: .................................... ^ syntax error


    Bianca

  6. #6
    Just Joined!
    Join Date
    Mar 2008
    Posts
    30
    Hi

    awk -F"," -v gr=$GS_MOUNT_FOLDER_META '/MountFolderLive=\/live\//{$2=gr;}1' OFS="," file

    I managed to handle this.

    Thanks a lot

    Bianca

  7. #7
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Normally GNU utilities can be told to stop accepting switched by giving it a double hyphen
    Code:
    sed -e -- "s-\(^ResourceDIR=\)\([^#]*\)-\1${GR_RESOURCE_DIR}-" aaaa > bbbb

  8. #8
    Just Joined!
    Join Date
    Mar 2008
    Posts
    30
    Quote Originally Posted by bigtomrodney View Post
    Normally GNU utilities can be told to stop accepting switched by giving it a double hyphen
    Code:
    sed -e -- "s-\(^ResourceDIR=\)\([^#]*\)-\1${GR_RESOURCE_DIR}-" aaaa > bbbb

    This doesn't work:
    sed: -e expression #1, char 1: unknown command: `-'


    Bianca

Posting Permissions

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