Sed a variable which has - character in it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed a variable which has - character in it
# 1  
Old 03-13-2008
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
#XAC_INSTALL_PATH=/usr/XenonAdministrationCenter
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  
Old 03-13-2008
What exactly are you trying to do here?

Change "ResourceDIR=/app-nfs/meta/relay" to "ResourceDIR=new-app?
Change "ResourceDIR=/app-nfs/meta/relay" to "ResourceDIR=/new-app/meta/relay?
# 3  
Old 03-13-2008
Quote:
Originally Posted by fpmurphy
What exactly are you trying to do here?

Change "ResourceDIR=/app-nfs/meta/relay" to "ResourceDIR=new-app?
Change "ResourceDIR=/app-nfs/meta/relay" to "ResourceDIR=/new-app/meta/relay?

I want to replace everythig after ResourceDIR= with the variable read during install.

I want to specify that another parameter that need to be replace is
MountFolderLive=/live/, /app-nfs/meta/relay
and here only /app-nfs/meta/relay to be replaced with the variable read.

Thanks
Bianca

Last edited by potro; 03-13-2008 at 06:45 AM..
# 4  
Old 03-13-2008
Try the following:

Code:
sed -e "s|\(^ResourceDIR=\)\([0-9a-zA-Z\/\-]*$\)|\1${GR_RESOURCE_DIR}|" infile > outfile

# 5  
Old 03-14-2008
Quote:
Originally Posted by fpmurphy
Try the following:

Code:
sed -e "s|\(^ResourceDIR=\)\([0-9a-zA-Z\/\-]*$\)|\1${GR_RESOURCE_DIR}|" infile > outfile

Hi

This works for my first parameter ResourceDIR but not for the second one:
[root@skynet bianca]# cat aaaa
[Basic Configuration]
ResourceDIR=/app-nfs/meta/relay
MountFolderLive=/live/, /app-nfs/meta/live

For the second one /app-nfs/meta/live should be replaced with the read variable .

sed -e "s|\(^MountFolderLive=/live/,\)\([0-9a-zA-Z\/\-]*$\)|\1${GS_MOUNT_FOLDER_META}|" aaaa > bbbb

This doesn't work for this parameter.

Thanks,
Bianca
# 6  
Old 03-14-2008
What is this "read variable"? Please give example of expected output.

Nobody can help you unless you are more precise with your requests for help.

Quote:
For the second one /app-nfs/meta/live should be replaced with the read variable .
# 7  
Old 03-14-2008
[root@skynet bianca]# cat aaaa
[Basic Configuration]
ResourceDIR=/app-nfs/meta/relay
MountFolderLive=/live/, /xac-nfs/meta/live

[root@skynet bianca]# cat xac.sh
#!/bin/bash
GR_RESOURCE_DIR=/new-app/meta/relay
GS_MOUNT_FOLDER_META=/new-app/meta/live
> bbbb
cat aaaa

sed -e "s|\(^ResourceDIR=\)\([0-9a-zA-Z\/\-]*$\)|\1${GR_RESOURCE_DIR}|" \
-e "s|\(^MountFolderLive=/live/,\)\([0-9a-zA-Z\/\-]*$\)|\1${GS_MOUNT_FOLDER_META}|" aaaa > bbbb

cat bbbb

Expected output in bbbb file:
[Basic Configuration]
ResourceDIR=/new-app/meta/relay
MountFolderLive=/live/, /new-app/meta/live

Thanks,
Bianca
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

sed - replacement file path with variable - Escaping / character

Hi,, I have the line below in a file: $!VarSet |LFDSFN1| = '"E:\APC\Trials\20140705_427_Prototype Trial\Data\T4_20140705_Trial_Cycle_Data_13_T_Norm.txt" "VERSION=100 FILEEXT=\"*.txt\" FILEDESC=\"General Text\" "+""+"TITLE{SEARCH=NONE NAME=\"New Dataset\" LINE=1I want to write a script to change... (2 Replies)
Discussion started by: carlr
2 Replies

3. Shell Programming and Scripting

Sed: delete on each line before a character and after a character

Hi there, A total sed noob here. Is there a way using sed to delete everything before a character AND after another character on each line in a file? The deletion should also delete the indicating characters(here: an opening and a closing parenthesis). The original file would look like... (3 Replies)
Discussion started by: bnbsd
3 Replies

4. Shell Programming and Scripting

How to substitute variable in sed for special character?

Hi , I have input file like below Hi this is "vinoth". Hi happy to work with 'unix' USA(united states of America) My script variables are below : Dquote=Ộ Squote=&#$567 Obrac=&^986 Cbrac=&^745 I want to read the variables in my SED command to replace the double quote,single... (9 Replies)
Discussion started by: vinothsekark
9 Replies

5. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

6. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

7. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

8. UNIX for Dummies Questions & Answers

sed with variable containing space character

Hi all, I have the following script S1a="13 9 -0.0012041" S1b="13 8 -1.00000 " sed 's/${S1b}/${S1a}/g' funE00.i > tmp1 but the strings are not replaced. Maybe the problem is in the spaces cointaned in the variables? Thanks for your help, Sarah (2 Replies)
Discussion started by: f_o_555
2 Replies

9. UNIX for Dummies Questions & Answers

SED: Can't Repeat Search Character in SED Output

I'm not sure if the problem I'm seeing is an artifact of sed or simply a beginner's mistake. Here's the problem: I want to add a zero-width space following each underscore between XML tags. For example, if I had the following xml: <MY_BIG_TAG>This_is_a_test</MY_BIG_TAG> It should look like... (8 Replies)
Discussion started by: rhetoric101
8 Replies

10. UNIX for Dummies Questions & Answers

read a variable character by character, substitute characters with something else

im having trouble doing this: i have a variable with 2 characters repeating e.g. aababbbaaaababaabbaabbba is there a way i can search the variable for a's and b's and then change a's to b's and b's to a's? im guessing its like getting the 1's compliment of the string im doing this in... (2 Replies)
Discussion started by: vipervenom25
2 Replies
Login or Register to Ask a Question