Issue
I want to appends each line of the file as below:
file.txt :
adminsrv.tar
Output:
- archive: "packages/images/adminsrv.tar"
I tried several method like the one below and ended up with error:
input=/var/tmp/file.txt
while read -r line
Do
sed -i 's|$line|" - archive: "packages//images//$line"'
done < $input
Solution
You can just insert new text before every line using sed
and there is no need to run a shell loop:
sed 's~.*~- archive: "packages/images/&"~' "$input"
- archive: "packages/images/adminsrv.tar"
This sed
uses .*
for search for any text and then it substitutes matched text with replacement text and &
which is back-reference of the matched text.
Answered By - anubhava Answer Checked By - Marie Seifert (WPSolving Admin)