Linked Questions

1
vote
1answer
900 views

How to replace a word in a file by a word get by read function? [duplicate]

Situation: echo "tell me a word" read the_word How to replace all WordToReplace in a file by the_word? sed does not seems to appreciate: sed -i 's/WordToReplace/$the_word/g' thefile.sh
0
votes
1answer
35 views

How to insert comment at specific variable line number by sed command? [duplicate]

I want to comment out a line (add a # to the beginning). I used this command: sed -i '96s/^/#&/' file.txt on Linux to insert comment at line # 96. If the line number is a variable, then how can I ...
0
votes
1answer
59 views

I am not able to update a variable through sed command

I have assigned two variables but not able to update x=$(cat /scratch/env.properties | grep ConfigPath) y=$(ConfigPath=/scratch/a/b) then sed to replace ConfigPath in env.properties sed 's/$x/$y/' ...
0
votes
1answer
489 views

How to pass variable in pattern while using sed command?

I have file abc.sh search_dir='dummy' filename='numbers.txt' for entry in "$search_dir"/* do while read p; do sed -i '' "/$p/d" $entry done < $filename done Trying to delete a line ...
0
votes
1answer
414 views

Using sed to find and change information in configuration file [duplicate]

There is a file named partner like: abc def ghi There is another conf file like: part=abc var=x var=y id=123 part=def var=z id=345 and so on... I am making a shellscript which reads line from '...
0
votes
1answer
118 views

replace word with a variable in line start with [duplicate]

I need to know how to replace this line in fstab: tmpfs /dev/shm tmpfs defaults 0 0 with: tmpfs /dev/shm tmpfs defaults,...
0
votes
1answer
2k views

sed replace with variable [duplicate]

I am trying to replace matching string with other string. This is what I have ZKHOSTS="host1,host2,host3" old_string="tsd.storage.hbase.zk_quorum*" new_string="tsd.storage.hbase.zk_quorum = $ZKHOSTS" ...
0
votes
1answer
417 views

sed replace with value from an argument [duplicate]

Although this seems like a simple task, the sed call is not substituting the value that I send for IP. Instead, it is replacing localhost with "${IP}". substitute() { export IP=$1 echo $IP ...
-1
votes
1answer
24 views

Querry on using command “SED” for replacing text in bash shell [duplicate]

While using the command "sed" for find and replace, I wanted to know how one could find a constant and replace it with a variable inside the quotation syntax of sed? I wanted to replace constant 3 ...
-3
votes
1answer
43 views

Script to change $HOME in path to tilde ~ [duplicate]

I tried: $ echo $HOME | sed 's/$HOME/~/g but this didn't work, perhaps because of forward slashes? Does anyone have a script to do this either or: using bash builtins using sed Thank you
1
vote
0answers
31 views

sed replacing text in a file [duplicate]

I would like to replace <Path_To_BOOST_LIB_DIR> in a file with the content of ${PREFIX}/lib but this command sed -i .bak 's|<Path_To_BOOST_LIB_DIR>|echo ${PREFIX}/lib|' src/CMakeLists....
0
votes
0answers
33 views

How to use sed to replace variable value with a variable of the same name?

I'm trying to write a script that updates a server config file to the latest format. The purpose of the script is to copy over existing (defined) variables to the latest config (in a temp file), then ...
0
votes
0answers
17 views

remove pattern from string using sed and a variable [duplicate]

I want to remove a pattern from a string (using sed and pipes), but this pattern is not always the same and is defined previously on a variable. this example mimics the desired behavior toremove="...
0
votes
0answers
165 views

Use variable inside sed command [duplicate]

how can i use variables inside this sed command? sed -i.bak -e '/triggerword/,${w $DIR/tempfile' -e 'd;}' $DIR/targetfile inside -e '{w $DIR/tempfile' -e 'd;}' the $DIR/tempfile isn't recognized
0
votes
0answers
294 views

Sed is not replacing with the value of a variable [duplicate]

I'm using sed to modify a file. In simple terms, my modifier looks as so sed -e '11s/$/ $LinuxUsername/' This is suppose to add in their linux username at the end of line 11, however, it is instead ...

15 30 50 per page