Solved

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

Posted on 2014-04-03
6
185 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 500 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

717 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