Search code examples
linuxbashsedcommand

use bash function in sed command


I have a file called d1.txt

line1
line2

and a.sh

#!/bin/bash
read -p  'Name : ' domain
#Not Working Command: sed -i s/$/' >> domain-js-m1-1.js/ d1.txt

I want to add ' >> $domain-1.js in the last of every line in d1.txt using script a.sh
I try this cmd but this is not adding text from input

sed -i s/$/' >> $domain-1.js/ d1.txt

read -p 'Name: ' domain If I give shin in input
then I want this in output

line1' >> shin-1.js
line2' >> shin-1.js

Thanks In Advance


Solution

  • You just need to use backslash and double qoutes, like so:

    sed -i 's/$/'\'" >> $domain-1.js/" d1.txt