I tried to extract text from line N to line M in bash to a separate file, with N and M to be variable. For example, I want to extract from line 3 to line 5. I set
N=3
M=5
and do
sed -n 'N,Mp' input > output
It doesn't work for me.
I tried to extract text from line N to line M in bash to a separate file, with N and M to be variable. For example, I want to extract from line 3 to line 5. I set
N=3
M=5
and do
sed -n 'N,Mp' input > output
It doesn't work for me.
You can do this with sample awk
script:
awk -v s=$N -v n=$M 'NR>s && NR<n' input >output
with sed
will be something like:
sed -n "${N},${M}p" input >output