Skip to content

Commit 60ce9c3

Browse files
committed
Field swapping example
1 parent f067a2f commit 60ce9c3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

field_swap.awk

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Last field should become first and first become last.
2+
# Example: awk -f field_swap.awk files/passwd
3+
#
4+
# We are playing with an intermediate variable used to store the first field value
5+
6+
BEGIN{
7+
FS=":"
8+
OFS=FS
9+
}
10+
{
11+
last=$1
12+
$1=$NF
13+
$NF=last
14+
}
15+
{
16+
print
17+
}
18+

0 commit comments

Comments
 (0)