0

I want to delete third line of file named file2. Its running successfully.No Issues with it.

sed '3d' ../log/file2.txt > ../log/file8.txt

Now i want to use variable VAR1 (where VAR1=2).

I wrote the following command

sed "${VAR1+1}d" ../log/file2.txt > ../log/file8.txt

but this command deleting the 2nd line. No error while executing the command.But I am not getting expected output

Please help me How to use sed in this command to get the correct line to be deleted

4

2 回答 2

1

尝试

sed "$((VAR1+1))d" ../log/file2.txt
于 2013-09-30T11:51:49.270 回答
0

使用变量和删除一行awk

var1=4
awk NR!=v v=$var1 ../log/file2.txt > ../log/file8.txt

这将删除4thfile2

为了使其更健壮,请使用 qutes

awk 'NR!=v' v="$var1" file
于 2013-09-30T12:47:30.720 回答