Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-09-2009, 05:29 AM
|
#1
|
Member
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598
Rep:
|
sed help needed
Hi all,
Am on the way of learning sed using Bash-Beginners-Guide.pdf. Suddenly i got questions myself of how to print the lines , say 5-10 in a file using sed.
1.How to print a line ,say 28 only in a file using sed?
2.How to print from line 5-10 in a file ?
3.How can list all my files in my home directory using sed?
Can someone suggest me a dedicated document(pdf pref) for "sed"
Thanks
Last edited by ZAMO; 01-09-2009 at 05:34 AM.
|
|
|
01-09-2009, 05:33 AM
|
#2
|
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep: 
|
Here's a really good sed tutorial for you
http://www.ibm.com/developerworks/li...ry/l-sed1.html
Why would you use sed to list files in your home directory?
|
|
|
01-09-2009, 05:37 AM
|
#3
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Here is another really good sed tutorial:
http://www.grymoire.com/Unix/Sed.html
|
|
|
01-09-2009, 05:38 AM
|
#4
|
Member
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598
Original Poster
Rep:
|
Code:
Why would you use sed to list files in your home directory?
It is there in the Exercise part of the pdf and it is interesting to know , sed to list the files in a directory.
|
|
|
01-09-2009, 06:17 AM
|
#5
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
You might use sed to reformat the list of files in your home directory, but the list will be supplied either by file globbing or ls or find.
If you move on to learning awk as well, I would recommend downloading the source package for 'gawk' and using "make pdf" to produce the "GAWK: Effective Awk Programming".
The "Sed & Awk" O'Reilly book is very good. The first edition might be available as a pdf on the web.
|
|
|
01-09-2009, 06:34 AM
|
#6
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by jschiwal
If you move on to learning awk as well, I would recommend downloading the source package for 'gawk' and using "make pdf" to produce the "GAWK: Effective Awk Programming"
|
The pdf is also available online, here.
|
|
|
01-09-2009, 06:44 AM
|
#7
|
Member
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598
Original Poster
Rep:
|
Thank you colucix and jschiwal,
I am having this PDF for gawk for a very long time and used to go through it. It will be nice if I get a similar kind of one for "sed".
|
|
|
01-09-2009, 06:58 AM
|
#8
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
The grymoire site linked earlier also has a good section on AWK.
Back to the questions:
Quote:
1.How to print a line ,say 28 only in a file using sed?
2.How to print from line 5-10 in a file ?
|
What you want is called "addressing". The general form is:
sed '<address1>,<address2> action'
either <address1> or <address2> can be a line number or a Regex. <address2> can also be a numerical increment or interval.
Examples:
Code:
sed -n '3p' filename ##prints only line 3
sed -n '3,6p' filename ##prints lines 3-6
sed -n '/the/p' filename ##prints all lines containing "the"
sed -n '/the/,/end/p' filename ##prints lines beginning with one containing "the" and ending with one containing "end"
finally, note that Gnu SED has many extensions that do not appear in the Unix tutorials. For this, look at "info sed" in a terminal, or Google for the official Gnu SED manual.
|
|
|
All times are GMT -5. The time now is 03:55 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|