3

I am trying to delete two lines ( 7 and 8) from a .txt file. For this I am using following code:-

#!/bin/sh
Column="7"
sed '"$Column",8d' myfile.txt > result.txt

on running this script, I am getting this error:-

sed: -e expression #1, char 1: unknown command: `"'

Please tell me how to use variable as a part of sed command.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • Using double quotes within single quotes doesn't help, you'll have to keep the double quotes outside the single quotes. – muru Sep 04 '19 at 11:21
  • See [How can I use variables in the LHS and RHS of a sed substitution?](https://unix.stackexchange.com/questions/69112/how-can-i-use-variables-in-the-lhs-and-rhs-of-a-sed-substitution) – steeldriver Sep 04 '19 at 11:21

1 Answers1

4

Variables are not expanded in single quotes. Use this:

sed "${Column},8d" myfile.txt > result.txt
Arkadiusz Drabczyk
  • 25,049
  • 5
  • 53
  • 68