This link has been bookmarked by 148 people . It was first bookmarked on 02 Mar 2006, by Joel Liu.
-
31 Oct 09
-
18 Oct 09
-
13 Oct 09
-
12 Oct 09
-
'[0-9]*' is
the first character on the line, as this matches zero of more
numbers
-
-
11 Oct 09
-
18 Sep 09
-
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'
-
-
14 Sep 09
-
05 Sep 09
-
27 Aug 09
-
20 Aug 09
-
06 Aug 09
-
23 Jul 09
-
13 Jun 09
-
10 Jun 09
-
11 Apr 09
-
11 Feb 09
-
09 Feb 09
-
04 Feb 09
-
19 Jan 09
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.
-
-
16 Jan 09
-
11 Jan 09
-
16 Dec 08
-
10 Dec 08
-
16 Nov 08
-
23 Oct 08
-
18 Sep 08
-
10 Sep 08
-
08 Sep 08
-
04 Sep 08
-
19 Aug 08
-
13 Aug 08
-
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.
-
-
07 Aug 08
-
04 Aug 08
-
19 Jul 08
-
04 Jul 08
bubnoff korovievSed Tutorial
-
03 Jul 08
-
25 Jun 08
-
30 Apr 08
-
21 Mar 08
-
10 Mar 08
-
07 Mar 08
-
22 Feb 08
-
20 Feb 08
-
16 Feb 08
-
04 Feb 08
-
26 Jan 08
-
28 Dec 07
-
26 Nov 07
-
29 Oct 07
-
28 Oct 07
-
12 Oct 07
-
17 Sep 07
-
01 Sep 07
-
16 Aug 07
-
Sed - An Introduction and Tutorial
-
-
02 Aug 07
-
21 Jul 07
-
17 Jul 07
-
16 Jun 07
-
28 Apr 07
-
19 Apr 07
-
16 Apr 07
-
27 Mar 07
Asbjørn Clemmensensed is awesome, but has a pretty steep learning curve - this is my way to work with that fact
-
12 Mar 07
-
14 Feb 07
-
02 Feb 07
-
25 Jan 07
-
22 Dec 06
-
17 Nov 06
-
14 Nov 06
-
05 Nov 06
-
03 Nov 06
-
25 Oct 06
-
24 Oct 06
-
06 Oct 06
-
27 Sep 06
-
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,
-
-
16 Sep 06
-
06 Sep 06
-
30 Aug 06
-
23 Aug 06
-
21 Aug 06
-
08 Aug 06
-
07 Aug 06
-
Bruno MartinsHere is your chance to really understand sed.
computer linux programming scripting sed shell tutorial tutorials unix
-
06 Aug 06
-
04 Aug 06
-
01 Aug 06
-
18 Jul 06
Page Comments
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.