I have code that is meant to find line numbers in a file where 2 different files are equivalent, and then remove all but those line numbers from one of the files. To do so, I made a pre-made sed string I want to run in sed, but I am getting the error:
sed: -e expression #1, char 3: unknown command: `;'
My premade sed string looks like so
echo ${_sedstr}
1;2;7;11;12;13;15;17;22!d
My intention was to then use this variable in a sed command to remove all lines except those in the string within the file ${_edit}
sed -i.bak -e ${_sedstr} ${_edit}
I've tried all combinations of placing single / double quotes around ${_sedstr} and escaping the quotes with a backslash '\', but I still seem to have an issue with the code running as intended.
An example of what I am trying to achieve would be say ${_edit} looked like this:
hello
my
name
is
John
Doe
With the expression sed -i.bak -e '1;2;4!d' ${_edit}, I would expect the file to output to
hello
my
is
Deleting all lines besides 1, 2, and 4.