Skip to content

Commit

Permalink
Improved awk examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchpaulus committed Dec 4, 2024
1 parent 9621dfa commit f842f71
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ wt (:-1: wl) each
# 4. Print the last field of the last input line:
# { field = $NF }
# END { print field }
.. :-1: " " split :-1: wl
wt :-1: :-1: wl

# 5. Print every input line with more than four fields
# NF > 4
.. (dup ws split len [(4 >) (wl) (drop)] if) each
.. (wsplit len 4 >) filter (wl) each

# 6. Print every input line in which the last field is more than 4
# $NF > 4
Expand Down
4 changes: 2 additions & 2 deletions examples/awk.msh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ wt (:-1: wl) each
# 4. Print the last field of the last input line:
# { field = $NF }
# END { print field }
.. :-1: wsplit :-1: wl
wt :-1: :-1: wl

# 5. Print every input line with more than four fields
# NF > 4
.. (dup " " split len [(4 >) (wl) (drop)] if) each
.. (wsplit len 4 >) filter (wl) each

# 6. Print every input line in which the last field is more than 4
# $NF > 4
Expand Down
2 changes: 2 additions & 0 deletions examples/awk/4.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ field = $NF }
END { print field }
1 change: 1 addition & 0 deletions examples/awk/4.msh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Wt :-1: :-1: wl
1 change: 1 addition & 0 deletions examples/awk/5.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NF > 4
10 changes: 10 additions & 0 deletions examples/awk/5.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
1 change: 1 addition & 0 deletions examples/awk/5.msh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. (wsplit len 4 >) filter (wl) each
9 changes: 9 additions & 0 deletions examples/awk/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@ else
fi

emp_test 3
emp_test 4


if diff <(awk -f '5.awk' < 5.data) <(mshell 5.msh < 5.data); then
printf "5. pass\n"
else
printf "5. fail\n"
FAIL=1
fi

exit "$FAIL"

0 comments on commit f842f71

Please sign in to comment.