Quantcast
Channel: A Portal to a Portal
Viewing all articles
Browse latest Browse all 1850

Bash - Using Variables in Sed

$
0
0
Set a variable

export NAME=DAVE

Validate the variable

echo $NAME

DAVID

Initialise a file

echo "DAVE"> foobar.txt

Validate the file contents

cat foobar.txt

DAVE

Replace the contents of the file with the contents of the variable

sed -i''"s/DAVE/$NAME/g" foobar.txt

Validate the file contents

cat foobar.txt

DAVID

This works with Bash 4.1.2(1)-release on RHEL 6.6.

Viewing all articles
Browse latest Browse all 1850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>