How to use variable in sed command

Tabish Saifullah

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.

Arkadiusz Drabczyk

Variables are not expanded in single quotes. Use this:

sed "${Column},8d" myfile.txt > result.txt

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related