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

Posted on 2014-04-03
Medium Priority
Last Modified: 2014-11-08

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

the file has words of:

Dhcp Server \\ scope 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

Thank you
Question by:richsark
  • 2
LVL 68

Accepted Solution

woolmilkporc earned 2000 total points
ID: 39975526
grep -v "set natstate off" >

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'

This will create a backup file "" containing the orignal data and change "" in place.
LVL 20

Expert Comment

ID: 40010433
(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").
LVL 20

Expert Comment

ID: 40428899
Thanks for the points, but I think they should go to wmp not me!

Author Closing Comment

ID: 40430219
Hi. Sorry about that. Apologize for the mistake and delay.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question