-2

I have a report that pulls some information IP address and host name, etc. Some some servers have a heading like: NOTICE TO USERS (followed by about 17 lines of text information) when I cat the file, I do not need the NOTICE (and 17 more line after that on some servers). How can I get rid of it?

tester787
  • 449

2 Answers2

2
awk '/NOTICE TO USERS/ { lastdelline=NR+17 };
    lastdelline>0 && NR<=lastdelline { next; }; { print; }' inputfile
Hauke Laging
  • 90,279
  • Why NR+5 and not NR+17? – codeforester Apr 02 '18 at 15:42
  • 3
    @codeforester 5 is "about" 17 :-) – nohillside Apr 02 '18 at 15:44
  • I tried the awk commnad, it did not take out any thing. The NOTICE TO USERS (followed by 17 lines) is a part of /etc/issue. My script does ssh from on server to a number of servers and gathers information like IP, host name ,etc. I am still trying to get rid off NOTICE TO USERS (followed by 17 lines) which appears on some servers. I appreciate any help. – tester787 Apr 02 '18 at 16:23
  • awk '/NOTICE TO USERS/ { lastdelline=NR+17 }; lastdelline>0 && NR<=lastdelline { next; }; { print; }' test.info – tester787 Apr 02 '18 at 16:43
1

You can use below sed command to achieve the same

sed '/NOTICE TO USERS/,+17d' filename

IF you want to delete the 17lines with NOTICE TO USERS line in same file means you can use -i option in sed command

sed -i '/NOTICE TO USERS/,+17d' filename