Visit Our UNIX and Linux User Community

Passing a variable in SED getting command garbled

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing a variable in SED getting command garbled
# 1  
Old 10-25-2007
Passing a variable in SED getting command garbled

I fairly new to SED. I have tried many different variations of this line of code and even breaking it down into its components and running them separately.

They work individually without variables but when I place the $todbname variable it will either inserts the text "connect to $todbname" or it will give the command garbled as it has this time.

This is the code that is not working properly
-e '1i\
connect to "$todbname";'

The entire line of code and bourne trace is below.

This results in "connect to $todbname" being inserted on the first line of the file.

sed -e 's/^[ \t]*//;s/[ \t]*$//' -e '/./,/^$/!d' -e "/$fromdbuser/ s//$todbuser/g" -e '1i\
connect to $todbname;' fk_"$todbname".sql.orig > fk_"$todbname".sql

This results in the command garbeld error.
`sed -e 's/^[ \t]*//;s/[ \t]*$//' -e '/./,/^$/!d' -e "/$fromdbuser/ s//$todbuser/g" -e '1i\
connect to "$todbname";' fk_"$todbname".sql.orig > fk_"$todbname".sql`

+ sed -e s/^[ \t]*//;s/[ \t]*$// -e /./,/^$/!d -e /db8inst/ s//db8inst1/g -e 1iconnect to "$todbname"; fk_eldtest.sql.orig
sed: command garbled: 1iconnect to "$todbname";

Can anyone help me?

# 2  
Old 10-25-2007
-e "1i\
connect to ${todbname};"

# 3  
Old 10-25-2007
If I add

-e "1i\
connect as ${todbname};"

I get this, I now get the "eldtest" string in the ${todbname} but I still get the command garbled error.

+ sed -e s/^[ \t]*//;s/[ \t]*$// -e /./,/^$/!d -e /db8inst/ s//db8inst1/g -e 1iconnect to eldtest; fk_eldtest.sql.orig
sed: command garbled: 1iconnect to eldtest;

# 4  
Old 10-25-2007
Computer Fixed

Fixed it using various quote combinations. I used single for the entire command string, then areound the variable I use single, double, double and single. Now it works.

-e '1i\
connect to '"${todbname}"';' fk_"$todbname".sql.temp > fk_"$todbname".sql

Thanks for time and getting me in the right direction,

Previous Thread | Next Thread
Test Your Knowledge in Computers #507
Difficulty: Easy
In the following code: x = 3y + 7; the variables x and y represent numbers that can take on a number of different values.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command garbled when using sed

Hi everyone, Can anyone help me in question below? I want to cron a job to add partition every month but get the error sed: command garbled: s/YYYYMM/ . > echo $YYYYMON_NEW 201304 > echo $YYYYMON_OLD 201208 > echo $YYYY_MM_NEW 2013-05 This is my base script: ALTER TABLE STS.ADMIN ADD... (1 Reply)
Discussion started by: fenocean
1 Replies

2. Shell Programming and Scripting

sed help - Command garbled

Hi, First post for a noob so please go easy with me :) I have a XML block that is originally like this: <SETNAME>somecrap/THIS</SETNAME> and I would like it be replaced with, in the original file: <SETNAME>THIS</SETNAME> I tried to use: sed... (4 Replies)
Discussion started by: zhuanyi
4 Replies

3. Shell Programming and Scripting

sed: command garbled error

Hi all, Suppose that I want to update the db.password entry in the below properties file, db.username=admin db.password=qhKkBno2U5GEq5k/dnmGPA== //I want this line to be replaced by: "db.password=abc/123/" db.port=22 db.sid=database However when... (2 Replies)
Discussion started by: isaacniu
2 Replies

4. Shell Programming and Scripting

sed command garbled error

sed: command garbled: s/ri="*"/ri=" what i did is you can see below sed "s/ri=\"*\"/ri=\"$newri\"/" $2 > output how to solve this (2 Replies)
Discussion started by: pasricha.kunal
2 Replies

5. Shell Programming and Scripting

passing variable to sed command not working

Hello All, I am trying to embed variable in sed command to fetch a portion of record between two pattern. This command is not working ...any suggestion on this how to place the variable in sed command to find a portion . I am using Sun OS (Solaris). Thanks JM (1 Reply)
Discussion started by: jambesh
1 Replies

6. Shell Programming and Scripting

Passing a variable to sed command

Hi guys, I wanted to pass a variable to the sed command which tells which line to be deleted. a=2; echo $a; sed '$ad' c.out it is throwing an error. sed: 0602-403 "$a"d is not a recognized function. I even tried "$a" and \$a.. but it is of no use. Can you please correct me... (6 Replies)
Discussion started by: mac4rfree
6 Replies

7. Shell Programming and Scripting

sed: command garbled

Hi, I have a file1 as : A=/home/user B=/home/user1 C=/home/user2 D=/home/aacsms E=/home/user1/temp F=/home/user1/area1 and my script as: a=`cat /home/aacsms7/file1 | grep -i e` b=`user2` sed 's/'$a'/"E=/home/'$b'/temp"/g' < file1 > file2 sed: command garbled:... (3 Replies)
Discussion started by: yesmani
3 Replies

8. Shell Programming and Scripting

Sed: command garbled :s/

Hi, I really need some help, I am using a very basic script to proess a text file. This script has been used many times but all of a sudden all on it's own it's stopped working. The line in the script is: sed 's/ //g' $ORGFILE > $NEWFILE and the error is Sed: command garbled :s/ All... (3 Replies)
Discussion started by: heidi.lightfoot
3 Replies

9. Shell Programming and Scripting

Passing a variable to sudo sed command

hi, dataParse(){ line="$@" name="cat /etc/passwd | grep "$line": | cut -f6 -d':'" eval $name > sam.txt 2>&1 sudo -u $line sed -n 's/data-1/&/p' $name/test.xml >> sam1.txt } Here i getting the homedir of the accounts and is set in name variable.which returns "/home/raju" which i... (3 Replies)
Discussion started by: sachin.tendulka
3 Replies

10. Shell Programming and Scripting

sed: command garbled

Im getting this error message when trying to substitute filepaths in a sed search and replace string #!/usr/bin/ksh ORACLE_SID=PH3 ORACLE_ADMIN=/data01/app/oracle/admin/$ORACLE_SID DATAFILE_DIR=/asterisk/oradata/$ORACLE_SID sed -e s/DBNAME/$ORACLE_SID/g < initPH2.ora | sed -e... (1 Reply)
Discussion started by: blakmk
1 Replies

Featured Tech Videos