Link to home
Start Free TrialLog in
Avatar of LeviDaily
LeviDailyFlag for United States of America

asked on

Debian VI Editor Append

I have a text file file I would like to edit on a Debian image for many devices. Instead of editing the file, I would like to have a script that edits it for me..

If I open the file, I need to delete Lines 3 & 4. Is there a way for a script to do it for me?
SOLUTION
Avatar of Xaelian
Xaelian
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of serialband
serialband
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Here you can see all the examples for sed. You don't need the -i flag.

http://en.kioskea.net/faq/1451-sed-delete-one-or-more-lines-from-a-file
Avatar of LeviDaily

ASKER

Thanks guys!! It worked great!!
Guys - I have another question regarding SED.. If you can help that would be great.. it is below

https://www.experts-exchange.com/questions/27828374/Debian-SED-command-Multiple-line-search-and-replace.html
Why accept everyones answer? I gave the command that everyone copied. I even showed that someones answer with just -i added wasn't necessairy.
Xaelian

Technically, our answers weren't quite copies.  This is a discussion forum and you aren't the only one that knows some sed.  It's like the old usenet, but better moderated and you can get points for providing answers when you participate.

Your version calls sed twice for each file.  I suggested calling it once instead, saving some file opens and closes, which could become significant if you had many files.  The best answer was probably from tintin, since the -i can save some lines of code if that's what you need to do.  He explained what it did and didn't say you had to use it.  We added on to the discussion at hand.

I should point out the -i is only available in gnu sed, basically linux.  It's not standard in posix compliant unix, like solaris, making the posix code more tedious to write, when you're not allowed to install gnu utilities.