I'd like to use "ed" to move lines up and down in linefeed-delimited text held in a variable. For example, to move line two down:.
input from variable:
one
two
three
four
output to variable:
one
three
two
four
The following one-liner works beautifully for a file, but I'd like to feed it a variable.
printf '%s\\n' '2,2m3' 'wq' | /bin/ed -s '/inputFile'
I've tried assorted variations on
printf '%s\\n' '2,2m0' 'wq' | /bin/ed -s <<<$inputVariable
which don't work, and my redirection expertise is clearly insufficient to the puzzle.
I'm running macOS 10.15.1.
echo $SHELL? I don't use Mac, but we did run into another question recently where MacOS was defaulting tozshinstead ofbashwhich would explain why your herestring was not working with a variable.