I'm trying to pipe multiple lines into a text file while manipulating the string that is being piped according to a sequence
cmd="My string 00"
for i in $(seq -f "%02g" 00 05); \
do \
echo $(echo $cmd | sed -e 's|00|$(echo $i)|g') >> outfile.txt ; \
done
doesn't work. The output should look like this:
My string 00
My string 01
My string 02
My string 03
My string 04
My string 05
but the output is:
My string $(echo $i)
My string $(echo $i)
My string $(echo $i)
My string $(echo $i)
My string $(echo $i)
My string $(echo $i)
"
instead of'
in yoursed
command. See https://askubuntu.com/questions/76808/how-do-i-use-variables-in-a-sed-command – Jos Jul 21 '18 at 15:13seq -f "%02g"
. – danzel Jul 21 '18 at 15:15seq -f "%05g" 00 05 | sed 's/.../My string /'
– Cyrus Jul 21 '18 at 16:39