diff options
| author | dms061 <dms7225@psu.edu> | 2021-05-16 18:47:40 -0400 |
|---|---|---|
| committer | dms061 <dms7225@psu.edu> | 2021-05-16 18:47:40 -0400 |
| commit | 0602d0d635835efc141bf1a89f604cd3156ecd3e (patch) | |
| tree | a3cf4fbbe6f6378b1e7f0180ab722010493d6c7d /challenge-112/abigail/awk/ch-1.awk | |
| parent | 111673b82066733c69a62c8f1030da605767aaf8 (diff) | |
| parent | fa969a62c402d6220e260e0f302c80e9b6133c90 (diff) | |
| download | perlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.tar.gz perlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.tar.bz2 perlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.zip | |
Merge branch 'manwar:master' into challenge112
Diffstat (limited to 'challenge-112/abigail/awk/ch-1.awk')
| -rw-r--r-- | challenge-112/abigail/awk/ch-1.awk | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-112/abigail/awk/ch-1.awk b/challenge-112/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..fde01cf5de --- /dev/null +++ b/challenge-112/abigail/awk/ch-1.awk @@ -0,0 +1,44 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +BEGIN { + FS = "/" # So we split into directory parts +} + +{ + delete path + j = 0 # Tracks the number of parts in + # the canonical part. + for (i = 1; i <= NF; i ++) { # Loop over directory parts + if ($i == "") { # Skip empty parts + continue; + } + if ($i == ".") { # Skip current directory + continue; + } + if ($i == "..") { # Back up to parent directory + if (j > 0) { + j -- + } + continue; + } + path [j] = $i # Copy + j ++ + } + if (j == 0) { # Root directory + print "/" + } + else { # Print parts, preceeded by a / + for (k = 0; k < j; k ++) { + printf "/%s", path [k] + } + print "" + } +} |
