?
Solved

Debian VI Editor Append

Posted on 2012-08-13
8
Medium Priority
?
618 Views
Last Modified: 2012-08-14
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?
0
Comment
Question by:LeviDaily
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 13

Assisted Solution

by:Xaelian
Xaelian earned 668 total points
ID: 38289056
you can use this. This will delete the 3rd line and the 4th line.

sed '3d' fileName.txt
sed '4d' fileName.txt
0
 
LVL 31

Assisted Solution

by:serialband
serialband earned 668 total points
ID: 38289076
Those could be combined into one command.

sed '3,4d' fileName.txt
0
 
LVL 48

Accepted Solution

by:
Tintin earned 664 total points
ID: 38289139
Use

sed -i 3,4d file

The -i flag will replace the file with the edited version, ie: with lines 3 & 4 deleted.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 13

Expert Comment

by:Xaelian
ID: 38289167
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
0
 
LVL 2

Author Comment

by:LeviDaily
ID: 38292361
Thanks guys!! It worked great!!
0
 
LVL 2

Author Comment

by:LeviDaily
ID: 38292514
Guys - I have another question regarding SED.. If you can help that would be great.. it is below

http://www.experts-exchange.com/OS/Linux/Q_27828374.html
0
 
LVL 13

Expert Comment

by:Xaelian
ID: 38292694
Why accept everyones answer? I gave the command that everyone copied. I even showed that someones answer with just -i added wasn't necessairy.
0
 
LVL 31

Expert Comment

by:serialband
ID: 38294263
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 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