This link has been bookmarked by 165 people . It was first bookmarked on 02 Mar 2006, by Joel Liu.
-
-
'[0-9]*' is
the first character on the line, as this matches zero of more
numbers
-
-
-
Printing with p
Another useful command is the print command:
"p." If
sed wasn't started with an
"-n" option, the
"p" command will duplicate the input. The command- sed 'p'
will duplicate every line. If you wanted to double every empty line,
use:- sed '/^$/ p'
Adding the
"-n" option turns off printing unless you request it.
Another way of duplicating
head's functionality is to print only the lines you want.
This example prints the first 10 lines:- sed -n '1,10 p' <file
Sed can act like
grep by combining the print operator to function on all lines that
match a regular expression:- sed -n '/match/ p'
- sed 'p'
-
-
Neil SaundersIf you want to write a program to make changes in a file, sed is the tool to use.
-
Komlan MISSINHOUNSed Tutorial
-
Calamity FactorsAnyhow, sed is a marvelous utility. Unfortunately, most people never learn its real power. The language is very simple, but the documentation is terrible. The Solaris on-line manual pages for sed are five pages long, and two of those pages describe the 34 different errors you can get. A program that spends as much space documenting the errors than it does documenting the language has a serious learning curve.
-
Anyhow,
sed is a marvelous utility.
Unfortunately, most people never learn its real power.
The language is very simple, but the
documentation is terrible. The Solaris on-line manual pages for
sed are five pages long, and
two of those pages describe the 34 different errors you can get.
A program that spends as much space documenting the errors than it
does
documenting the language has a serious learning curve.
-
-
W. Sarkased tutorial
-
Robert Feltyecho "123 abc" | sed 's/[0-9][0-9]*/& &/'
-
-
How can you put the string you found in the replacement string
if you don't know what it is? -
he solution requires the special character
"&." It corresponds to the pattern found.
-
-
bubnoff korovievSed Tutorial
-
gialloporporaTutorial veloce ed essenziale per imparare ad usare Sed.
-
Greg GannicottIndepth site.
-
-
Sed - An Introduction and Tutorial
-
-
Tim FoxSed tutorial
-
Asbjørn Clemmensensed is awesome, but has a pretty steep learning curve - this is my way to work with that fact
-
-
Anyhow, sed is a marvelous utility. Unfortunately, most people never learn its real power. The language is very simple, but the documentation is terrible. The Solaris on-line manual pages for sed are five pages long, and two of those pages describe the 34 different errors you can get. A program that spends as much space documenting the errors than it does documenting the language has a serious learning curve.
Do not fret! It is not your fault you don't understand sed. I will cover sed completely. But I will describe the features in the order that I learned them. I didn't learn everything at once. You don't need to eithe -
The
"=" command prints the current line number to standard output.
One way to find out the line numbers that contain a pattern is to use:- # add line numbers first,
# then use grep,
# then just print the number
cat -n file | grep 'PATTERN' | awk '{print $1}'
The
sed solution is:- sed -n '/PATTERN/ =' file
- # add line numbers first,
-
-
Bruno MartinsHere is your chance to really understand sed.
Page Comments
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.