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
...
- 03-13-2008 #1Just 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
- 03-13-2008 #2Linux 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
- 03-13-2008 #3Just 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
- 03-13-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:# awk -F"=" -v gr=$GR_RESOURCE_DIR '/ResourceDIR/{$2=gr;}1' OFS="=" file ResourceDIR=new-app
- 03-13-2008 #5Just Joined!
- Join Date
- Mar 2008
- Posts
- 30
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
- 03-13-2008 #6Just 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
- 03-13-2008 #7Linux 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
- 03-13-2008 #8Just Joined!
- Join Date
- Mar 2008
- Posts
- 30


Reply With Quote
