01-28-2009
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:
PX_LIST="7777 2259 2215 270 263 2874"
The command works fine if the value 777 is hardcoded:
echo 'PX_LIST="2259 221 270 263 2874" ' | sed 's/PX_LIST="/&7777 /'
Thanks for any help and advice -A
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I'm trying to change a part of a line with sed. Usually I will run
sed 's/mytext/mynewtext/'
Now I have a variable: var=mynewtext
sed 's/mytext/$var/' does not work. I have also tried to protect the $ with different characters but it still does'nt work.
I will be very happy if... (2 Replies)
Discussion started by: tromag
2 Replies
2. Shell Programming and Scripting
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... (2 Replies)
Discussion started by: aoussenko
2 Replies
3. Shell Programming and Scripting
hello
i have following sed command works fine.
sed -n 's/.*-L\(*\)myproject.*/\1/p' makefile > m
here search words are -L and myproject
now i want to replace these words by variables like
var1="-L"
var2="myproject"
so the command would be like this
sed -n... (3 Replies)
Discussion started by: shailesh_arya
3 Replies
4. Shell Programming and Scripting
Hello,
i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem.
my var1 is a string constructed like this:
filename1 filerev1 filepath1
my var2 is another string constructed like this:
filename2 filerev2 filepath2
when i do... (2 Replies)
Discussion started by: alrinno
2 Replies
5. Shell Programming and Scripting
i need to use a value in the Variable to print a particular line from a file using sed command.
i tried the below one but its is not working
sed -n ' "$var"p ' abc.txt
but its is not working please help me to sort out this. (3 Replies)
Discussion started by: Kochu77
3 Replies
6. Shell Programming and Scripting
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
7. Shell Programming and Scripting
I'm trying to make a sed substitution where the substitution pattern is an environment variable to be expanded, but the variable contains a "slash".
sed -e 's/<HOME_DIRECTORY>/'$HOME'/'This gives me the following error:
sed: -e expression #1, char 21: unknown option to `s'Obviously this is... (2 Replies)
Discussion started by: Ilja
2 Replies
8. Red Hat
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
9. UNIX for Advanced & Expert Users
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