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?
Asked
Active
Viewed 91 times
-2
-
"about 17 lines"...? – Hauke Laging Apr 02 '18 at 15:37
-
2We expect the question's requirements to be more precise. Show some sample text and explain which lines you want to exclude. – glenn jackman Apr 02 '18 at 15:43
2 Answers
2
awk '/NOTICE TO USERS/ { lastdelline=NR+17 };
lastdelline>0 && NR<=lastdelline { next; }; { print; }' inputfile

Hauke Laging
- 90,279
-
-
3
-
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

Praveen Kumar BS
- 5,211