Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-04-03
6
Medium Priority
?
195 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 20

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 20

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Utilizing an array to gracefully append to a list of EmailAddresses
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…
Six Sigma Control Plans

618 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