sed,awk

Hi,

I know sed is stream text editor and not a bit more than that. Can anyone explain its usage and advantages?

How is awk different from sed?

I donno i am a bit confused about it. But i have coded in awk and shell.

Thanks,
Nisha

:confused:

do you know ?
man :smiley:

i aint clear.. what r u trying to say?

-Nisha

This is a very brief diffrences between sed and awk text processing utilities.

sed: a non-interactive text file editor

awk: a field-oriented pattern processing language with a C-like syntax

For all their differences, the two utilities share a similar invocation syntax, both use regular expressions , both read input by default from stdin, and both output to stdout. These are well-behaved UNIX tools, and they work together well. The output from one can be piped into the other, and their combined capabilities give shell scripts some of the power of Perl.

One important difference between the utilities is that while shell scripts can easily pass arguments to sed, it is more complicated for awk.

Note:
Awk is a full-featured text processing language with a syntax reminiscent of C. While it possesses an extensive set of operators and capabilities, we will cover only a couple of these here - the ones most useful for shell scripting.

Awk breaks each line of input passed to it into fields. By default, a field is a string of consecutive characters separated by whitespace, though there are options for changing the delimiter. Awk parses and operates on each separate field. This makes awk ideal for handling structured text files, especially tables, data organized into consistent chunks, such as rows and columns.

Strong quoting (single quotes) and curly brackets enclose segments of awk code within a shell script.

While...

Sed is a non-interactive line editor. It receives text input, whether from stdin or from a file, performs certain operations on specified lines of the input, one line at a time, then outputs the result to stdout or to a file. Within a shell script, sed is usually one of several tool components in a pipe.

Sed determines which lines of its input that it will operate on from the address range passed to it. Specify this address range either by line number or by a pattern to match. For example, 3d signals sed to delete line 3 of the input, and /windows/d tells sed that you want every line of the input containing a match to "windows" deleted.

Of all the operations in the sed toolkit, we will focus primarily on the three most commonly used ones. These are printing (to stdout), deletion, and substitution.

Hi nisha,

man awk
man sed

gives some explanation.

Hi,

Awk can be incorporated in a shell. At the same time it can be written using C. The latter one sounds easy because the syntax for incorporating awk in a shell is difficult. I experienced this practically.

Am i right?

-Nisha

Yes nisha. you are absoulutely rite.

An awk program performs the given operation and consist of one or more awk statements. Following awk program extracts letters sent by a given machine from standard Unix mail file. System has two states, state 0 is searching and state 1 is printing selected mail. Variable p is the state variable. Note, that the end pattern may be part of the start pattern when there are two letters from the selected machine immediately after each other. Thus the order of pattern matching statements is important. If several statements are expected to match the same line, they must be in order of selectivity, most selective last.

   BEGIN { print FILENAME; p = 0 }
             /From / && / 199/           { p = 0 }
             /From / && /rde.axd.kill.net/  { p = 1 } 
     { if (p > 0) print $0
  END   { print "End ..." }

Hope does give you some idea.

Hey Thanks Killerserv...

Wish i could expertise unix to a very high level......

-Nisha:D