Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
Home
About
Free eBook
Archives
Best of the Blog
Contact
Ads by Google
Linux Hosting
Unix Tutorial
Unix or Linux
Like
Tweet
1/12/2012 12:27 AM
2 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
Sed reads a line and place it in a pattern buffer and writes the pattern buffer to the given output file according to
the supplied commands.
Let us first create thegeekstuff.txt file that will be used in all the examples mentioned below.
# cat thegeekstuff.txt
1. Linux - Sysadmin, Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Hardware
4. Security (Firewall, Network, Online Security etc)
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
10.Windows- Sysadmin, reboot etc.
1/12/2012 12:27 AM
3 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
4. Write the lines from which the pattern matches to till end of the file
In this example, /Storage/,$ represents line matches from Storage to end of the file.
$ sed -n '/Storage/,$w output.txt' thegeekstuff.txt
$ cat output.txt
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
10.Windows- Sysadmin, reboot etc.
5. Write the lines which matches pattern and next two lines from match
In this example, the send command writes the line matches for Storage and two lines next to that.
$ sed -n '/Storage/,+2w output.txt' thegeekstuff.txt
$ cat output.txt
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
1/12/2012 12:27 AM
4 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
Tweet
Like
Share
Comment
Tags: Linux Sed Command, Multicommand in Sed, Sed Examples, Sed Tips and Tricks, Unix Sed Command
{ 1 comment read it below or add one }
1 M.Sivagami July 21, 2011 at 7:19 am
Hi,
May i know how to substitute a \n with multiple new lines.
1/12/2012 12:27 AM
5 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
Thanks in advance
Leave a Comment
Name
E-mail
Website
Sign Up
Search
EBOOKS
1/12/2012 12:27 AM
6 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
1/12/2012 12:27 AM
7 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
POPULAR POSTS
12 Amazing and Essential Linux Books To Enrich Your Brain and Library
50 UNIX / Linux Sysadmin Tutorials
50 Most Frequently Used UNIX / Linux Commands (With Examples)
How To Be Productive and Get Things Done Using GTD
30 Things To Do When you are Bored and have a Computer
Linux Directory Structure (File System Structure) Explained with Examples
Linux Crontab: 15 Awesome Cron Job Examples
Get a Grip on the Grep! 15 Practical Grep Command Examples
Unix LS Command: 15 Practical Examples
15 Examples To Master Linux Command Line History
Top 10 Open Source Bug Tracking System
Vi and Vim Macro Tutorial: How To Record and Play
Mommy, I found it! -- 15 Practical Linux Find Command Examples
15 Awesome Gmail Tips and Tricks
15 Awesome Google Search Tips and Tricks
RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams
Can You Top This? 15 Practical Linux Top Command Examples
Top 5 Best System Monitoring Tools
Top 5 Best Linux OS Distributions
How To Monitor Remote Linux Host using Nagios 3.0
Awk Introduction Tutorial 7 Awk Print Examples
How to Backup Linux? 15 rsync Command Examples
The Ultimate Wget Download Guide With 15 Awesome Examples
Top 5 Best Linux Text Editors
Packet Analyzer: 15 TCPDUMP Command Examples
The Ultimate Bash Array Tutorial with 15 Examples
3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id
Unix Sed Tutorial: Advanced Sed Substitution Examples
UNIX / Linux: 10 Netstat Command Examples
The Ultimate Guide for Creating Strong Passwords
6 Steps to Secure Your Home Wireless Network
Turbocharge PuTTY with 12 Powerful Add-Ons
1/12/2012 12:27 AM
8 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
Support Us
Support this blog by purchasing one of my ebooks.
Bash 101 Hacks eBook
1/12/2012 12:27 AM
9 of 9
http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-how-to-write-to-a-...
Contact Us
Email Me : Use this Contact Form to get in touch me with your comments, questions or suggestions about
this site. You can also simply drop me a line to say hello!.
Follow us on Twitter
Become a fan on Facebook
Copyright 20082012 Ramesh Natarajan. All rights reserved | Terms of Service | Advertise
1/12/2012 12:27 AM