Search code examples
unixsedcsh

passing variable to this particular sed command


I am first searching for a key word and once that key word is found in a file from that particular line i am supposed delete till end of file.

#! /bin/csh -f
set sa = `grep -n -m 1 "^Pattern" file`
set s = `echo "$sa" | cut -d':' -f1`   
set m = `sed '$s,$d' file | tee see > /dev/null`

so first line gives me the matching line with line number, second line i am getting the line number and third line i am trying to delete from line $s say 20 till last but it is not working. I have tried all combinations but it does not take the variable $s. Please help.


Solution

  • You need to take $s out of the quotes so it will be expanded.

    set m = `sed $s',$d' file | tee see > /dev/null`