Awk Mode



Sed

sed
Start a sed script.
-e
Expression to evaluate.
-f
Use the following file.
-n
Only print matches once. Avoid double line output.
'
Single quote to start sed script.
"
Double quote to invoke shell interpretation of sed script.

Awk

awk
Start an Awk command.
-f
Use file specified after option.
-F
Data file field separator.
-v
Assign a value to variable.
BEGIN
Insert a begin structure.
END
Insert an end structure.
'
Single quote to start AWK script.
"
Double quote to invoke shell interpretation of AWK script.

Sed Operators

s/
Substitute regular expression operator.
y/
Transform operator - y/abc/ABC/g.
/
Expression separator - s/<\/html>/\vfill\eject/.
!
Alternative expression separator - s!!\vfill\eject!.
/g
Global substitution.
/p
Print the contents of the pattern space.
/w
Write pattern space to file.
/d
Delete regexp from pattern space.
/i\
Insert text into regexp match.
/a\
Append text to regexp match.
/c\
Change matched text to text.
/q
Quit script on match.
N
Append next line to pattern space.
P
Print multiple lines of pattern space.
D
Multi-line delete of pattern space.
&
Replace with string matched by regexp.

Awk Operators

{
Start an action.
}
End an action.
~
Insert field match operator.
!~
Insert field NOT match operator.
/
Start a regular expression match.
print
Insert the print command.
$0
Reference the entire input line.
$1
Reference the 1st column field.
$2
Reference the 2nd column field.
$3
Reference the 3rd column field.
$4
Reference the 4th column field.
$5
Reference the 5th column field.
$6
Reference the 6th column field.
$7
Reference the 7th column field.
$8
Reference the 8th column field.
$9
Reference the 9th column field.

Counting

.
Match anything except the newline character.
?
One match allowed, but its optional.
*
Zero or more matches allowed.
+
One match required, additional are optional.

Anchors

^
Insert start of line position marker.
$
Insert end of line position marker.
^$
Match a blank line.
^.*$
Match an entire line.

Classes

.
Match anything except the newline character.
[
Start a character class.
[^
Start a negated character class.
]
Close a character class.
-
Create a character range like a-h.
a-z
Match any lowercase letter.
A-Z
Match any uppercase letter.
0-9
Match any digit.

Grouping

(
Start a group or back reference.
)
End a group or back reference.
\(
Start a sub-pattern.
\)
End a sub-pattern.
{
Start protecting regexp from being interpreted.
}
End protecting regexp from being interpreted.

Other

&
regsub - Replaced with matched pattern.
\1
Replaced with 1st sub-pattern in pattern.
\2
Replaced with 2nd sub-pattern in pattern.
\3
Replaced with 3rd sub-pattern in pattern.
\
Used to escape special characters like \n.
|
Alternate (or) - a|b|c matches either a or b or c.


Index