• Aucun résultat trouvé

sed and awk

N/A
N/A
Protected

Academic year: 2022

Partager "sed and awk"

Copied!
7
0
0

Texte intégral

(1)

sed and awk

Henning Schulzrinne

Dept. of Computer Science

(2)

sed: string replacement

 Line-oriented tool for pattern matching and replacement (stream editor)

 Not really a programming language (cf.

awk)

 E.g., apply same change to lots of source files

 Filter, i.e., does not modify input file

(3)

sed description

pattern a text  add to output

address s /regex/replacement/

address d  delete line

delete lines 1-10: sed -e '1,10d‘

delete comments: sed -e '/^#/d‘

print only matching: sed -n -e '/regexp/p

(4)

awk

Special-purpose language for line-oriented pattern processing

pattern {action}

action =

if (conditional) statement else statement

while (conditional) statement

break

continue

variable=expression

print expression-list

(5)

awk

Patterns = boolean combinations of regular expressions and relational expressions

awk –f program < input > output

Also delimiter-separated fields:

BEGIN {FS=c}

Examples:

Print lines longer than 72 characters:

length > 72

(6)

awk examples

 Add up first column, print sum and average

{s += $1 }

END {print “sum is”, s, “average is”, s/NR}

 Print all lines between start/stop words:

/start/,/stop/

 Print all lines whose first field differs from previous one:

$1 != prev {print; prev = $1}

(7)

awk applications

 Unix file processing, e.g., as part of a pipe

 avoid read loop in shells, Perl

 more intuitive syntax than shell scripts

 best limited to line-at-a-time processing

Références

Documents relatifs

For achieving an efficient implementation on the mobile device, we spread the task of pattern matching over a filter hierarchy that is fed with the stream of GPS input data: Firstly,

Given a word of length n on an alphabet of size σ, our algorithm computes the set of minimal absent words in a sliding window of size m in O(σn) time and O(σm) space.. 4 Applications

It is defined as a record with five elements: (i) the structure schema ss , which defines the pattern space by describing the structure of the instances of the pat- tern type; (ii)

More specifically, we show how these concepts are effective at both unifying event and data-flow, and deriving complex reactive control structures such as a Finite State Machine.. ∙

Now that we have introduced our feature-based context-oriented programming approach, in this sec- tion we present the tool we built to help program- mers visualise and animate

Jadescript now provides a specific support for pattern matching that was carefully integrated with the type system of the language to readily state the conditions used to route

The presented tool combines a method for generating process models from natural language with a workflow oriented collaborative setting and shows new possibilities for process

If the Post grammar A of paragraphs 3.134 really describes a program- ming language, there should exist an algorithm to find the resuit of applying a program to a data structure,