Store output of sed into a variable [duplicate]

Use command substitution like this:

line=$(sed -n '2p' myfile)
echo "$line"

Also note that there is no space around the = sign.

Leave a Comment