how to dereference the variable in sed editor


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to dereference the variable in sed editor
# 1  
Old 06-16-2008
how to dereference the variable in sed editor

Hi
I am trying to do the substitution using the 'sed' editor. In the line below
I am trying to substitute all instances of XXX by the value of the variable PX

sed 's/XXX/${PX}/g' ${TEMPLETE} > ${TEMPLETE}.${PX}

The problem is that 'sed' editor takes ${PX} literary (without retrieving the value) and does the substitution. Is there any way to do it using 'sed' ?
May be somebody knows another approach to this ? Thanks a lot for help
-A
# 2  
Old 06-16-2008
The single quotes prevent the substitution of any shell variables in the sed script. Use double quotes instead.

Code:
sed "s/XXX/${PX}/g" ${TEMPLETE} > ${TEMPLETE}.${PX}

If PX contains any special characters (in particular, slash) you will need to escape or work around those somehow.

Also look into the correct spelling of "template". Furthermore, see UNIX Shell Quote
# 3  
Old 06-16-2008
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Kernel crash - NULL pointer dereference when calling DEVICE_WRITE from KTHREAD in a USB device drive

I'm writing a simple USB driver to drive a stepper motor based on USB Skeleton 2.2 Driver, kernel 3.8. The basic version is running properly. As a advancement, I introduced KTHREAD to call the DEVICE_WRITE (skel_write) (), so that the driver will be available for other tasks & requests. Calling... (0 Replies)
Discussion started by: miteshgaware
0 Replies

2. Shell Programming and Scripting

Insert charactera in 1st position of specific lines using vi editor or sed command

Dear all, i am having text file like below surya rama ranga laxman rajesh reddy i want add string (OK) before a text from line 3 to 5 the result will be surya rama OK ranga OK laxman OK rajesh reddy (1 Reply)
Discussion started by: suryanarayana
1 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Help with sed editor

I am a newbie to Unix and Linux, sed "32,45s///g" file : sed "s/\(\)-\(\)/\1\2/g" file How do we describe these commands in English ? Please help. (2 Replies)
Discussion started by: krthknaidu
2 Replies

5. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

6. Shell Programming and Scripting

how to dereference a variable in sed

Hi I have a 'sed' editor command trying to update a line in the file: NEW_PX=7777 echo 'PX_LIST="2259 221 270 263 2874" ' | sed "s/PX_LIST="/&${NEW_PX} /" The above command should add value of NEW_PX as the first entry inside the quotes, so the output should look like this: ... (2 Replies)
Discussion started by: aoussenko
2 Replies

7. UNIX for Dummies Questions & Answers

Defining EDITOR Variable - Tru64

Hi, I have to edit a lot of partitions soon and wanted to do so with EMACS rather than VI. The "disklabel -e -r disknumber" command picks up VI as it's defined, but how do I set "-e" so it uses EMACS instead please? Thanks...! (2 Replies)
Discussion started by: Bagel08
2 Replies

8. UNIX and Linux Applications

vi editor, grep or sed

I'm currently building a system to perfom a check on some operations on a unix system, i'm very new to unix and i need help. i know 'uname' displays the name of the OS been used, but how do u send the content of uname into a directory or file ? (1 Reply)
Discussion started by: dasadino
1 Replies

9. AIX

How to set path for the EDITOR variable?

For some reason something has changing in my AIX environment where when I type: ACLEDIT filename ...I get: 3002-104 acledit: EDITOR environment variable must be full pathname I know I need to reset the EDITOR variables path to /usr/bin/vi but I can't remember the syntax anyone? (2 Replies)
Discussion started by: heprox
2 Replies
Login or Register to Ask a Question