Linked Questions

19votes
2answers
97kviews

Passing a variable to sed [duplicate]

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt looks ...
user2013619's user avatar
4votes
2answers
24kviews

Why does a sed command work interactively but not in my script? [duplicate]

SED command not replacing in bash under Debian, but works in command line. Works in command line: sed -i 's|/dev/disk/by-label/SR6D4|/dev/disk/by-label/SR4D4|g' /etc/my/config.xml Not working in ...
klor's user avatar
  • 426
0votes
1answer
4kviews

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" ...
rp346's user avatar
  • 1,449
-3votes
1answer
2kviews

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
Nick's user avatar
  • 195
3votes
1answer
2kviews

Using sed with an integer variable [duplicate]

I want to sed using a variable. For example, sed -n '1,10p' file. So, instead of 10, I want to use $k where k is an integer.
Ea Saad's user avatar
1vote
1answer
954views

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
aurelien's user avatar
0votes
1answer
2kviews

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 ...
Vishal Patel's user avatar
0votes
0answers
1kviews

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 ...
TrevorKS's user avatar
1vote
2answers
446views

Sed command runs with hardcoded value in regex but fails with variable in script [duplicate]

My file data Pattern is below and i need output as 6 or 3 or 8 or 4 based on the variable value which is eth0 and eth1 eth0RX:6:eth0TX:3|eth1RX:8:eth1TX:4| Below code works well sed 's/.*eth0RX:\([0-...
Agnesh Kumar Singh's user avatar
0votes
1answer
922views

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 '...
geek's user avatar
0votes
1answer
893views

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 ...
Senthil Kumaran's user avatar
0votes
2answers
454views

content from pwd and which failed with sed to be replaced [duplicate]

I have a file which has the following content: BWA='/software/bwa/bwa-0.7.12/bwa' SAMTOOLS='/software/samtools/samtools-1.3.1/samtools' The above tools are on my computer: which bwa => /work/...
user977828's user avatar
-1votes
2answers
549views

appending into middle of a string using sed [duplicate]

I am completely new to sed script. I want to make a script so that it asks user to enter value to be inserted in file. I am not able to find the correct code so the line I have in the text file looks ...
Rishav Kondal's user avatar
0votes
1answer
470views

How can one pipe a random string to sed for substitution in a file? [duplicate]

I've tried this: echo $RANDOM | md5sum | head -c 20 | { read val; sed -i 's/__SALT__/$val/g' app.txt; } But this replaces __SALT__ with the string $val instead of the value in the variable.
geoidesic's user avatar
1vote
1answer
232views

Replacing string in a file with script [duplicate]

One of the ways replacing a string with sed can be done as follows: sed -i 's/old_str/new_str/' file.txt However if replace.sh is sed -i 's/$1/$2/' $3 the command ./replace.sh old_str new_str file....
Sphery's user avatar

153050per page