-2

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.

Barmar
  • 741,623
  • 53
  • 500
  • 612
user2508758
  • 91
  • 1
  • 2
  • 8

2 Answers2

2

But you can do it much more easier with a single line of sed:

sed -n '/SEARCHPATTERN/q;p
  1. -n tells to not print the lines
  2. /SEARCHPATTERN/q exits on search pattern
  3. ;p otherwise print the lines
Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
1

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

set m = `sed $s',$d' file | tee see > /dev/null`
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Sorry for tagging bash. It worked. Actually this is one of the several part of script which i am implementing in csh. – user2508758 Jun 13 '14 at 07:29