?
Solved

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

Posted on 2014-04-03
6
Medium Priority
?
192 Views
Last Modified: 2014-11-08
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
Comment
Question by:richsark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 39975526
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
 
LVL 19

Expert Comment

by:simon3270
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").
0
 
LVL 19

Expert Comment

by:simon3270
ID: 40428899
Thanks for the points, but I think they should go to wmp not me!
0
 
LVL 1

Author Closing Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Suggested Courses

771 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