• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

need script/shell to remove a line that contains a work

Hello,

I have a couple of files from a netsh dump of dhcp data

the file has words of:

Dhcp Server \\10.11.1.14 scope 10.25.0.0 set napstate Off

What I need is a script or another way  that will remove the whole line that contains "set natstate off" in my file called 10.11.1.14.dump

Thank you
0
richsark
Asked:
richsark
  • 2
1 Solution
 
woolmilkporcCommented:
grep -v "set natstate off" 10.11.1.14.dump > 10.11.1.14.dump.new

grep cannot change files in place, so we must create a new outputfile.

In order to change in place we could use "sed":

sed -i.bak '/set natstate off/d' 10.11.1.14.dump

This will create a backup file "10.11.1.14.dump.bak" containing the orignal data and change "10.11.1.14.dump" in place.
0
 
simon3270Commented:
(sed can't edit in place either - it just automates the renaming of the old file to .bak, or its deletion if no backup is to be produced, and renaming the new file to the same name as the original.  Same as "perl -i").
0
 
simon3270Commented:
Thanks for the points, but I think they should go to wmp not me!
0
 
richsarkAuthor Commented:
Hi. Sorry about that. Apologize for the mistake and delay.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now