Solved

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

Posted on 2014-04-03
6
165 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
  • 2
6 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
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
Comment Utility
(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
Comment Utility
Thanks for the points, but I think they should go to wmp not me!
0
 
LVL 1

Author Closing Comment

by:richsark
Comment Utility
Hi. Sorry about that. Apologize for the mistake and delay.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now