home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.questions:15859 comp.unix.shell:5470
- Newsgroups: comp.unix.questions,comp.unix.shell
- Path: sparky!uunet!mcsun!sunic!palantir.p.tvt.se!infolog!mich
- From: mich@lin.infolog.se (Thomas Michanek)
- Subject: Need help understanding sed
- Message-ID: <1993Jan22.210855.29212@infolog.se>
- Sender: news@infolog.se
- Organization: Infologics, Linkoping, Sweden
- References: <1993Jan22.140947@is.morgan.com>
- Date: Fri, 22 Jan 1993 21:08:55 GMT
- Lines: 44
-
-
- I've started to use 'sed' a lot, not only for simple 's/.../.../'
- substitutions, but I have trouble understanding the man page for sed
- when trying to using more complex commands. Could someone help me
- with the following issues:
-
- 1. The man page sais:
-
- Some commands use a hold space to save all or part of the
- pattern space for subsequent retrieval.
-
- However, I can't find _which_ commands do that and how. I've tried
- using the g, G, h, H, x commands, but sed produces no output.
-
- 2. "\n" in a context address is supposed to match a NEWLINE in the
- pattern space. But doesn't sed read one line at a time into the
- pattern space, each line separated by NEWLINE?
-
- I want to look for files containing the pattern "A" in one line
- and the pattern "B" in the next line. The following doesn't work:
-
- sed '/A\nB/p'
-
- How can you do such a 'multi-line grep'?
-
- 3. What's the difference between the commands n and p? The man page sais
- n copies the pattern space to stdout, but it has never worked for me.
-
- 4. What's the syntax for the { } command grouping? No matter how I try
- I get "Extra text at end of command" or "Unrecognized command".
-
- Isn't sed '/A/{=;p}' supposed to print the line number and the pattern
- on stdout? I've tried quoting, backslashing, spaces, no semicolon etc.
-
- BTW, I'm using C shell on SunOS4.1.1 and "sed0.c 1.15 89/03/28 SMI".
-
- Your aid is urgent and welcome!!!
-
- .- - - - - - - - - - - -. _ _ _ ___ _ _ _ _ _ _ _ .- - - - - - - -.
- | Thomas Michanek | | |\ | |_ / \ | / \ / _ | / `|_` | Dial +46 13 |
- | Infologics Linkoping | | | \| | \_/ |_,\_/ \_| | \_,._| | 210060 Phone |
- | email:Thomas.Michanek | _ | 210068 Direct|
- | @lin.infolog.se | L I N K O P I N G - S W E D E N | 210155 Fax |
- `- - - - - - - - - - - -' `- - - - - - - -'
-