aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-03 23:30:46 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-03 23:30:46 +1200
commit080bd0e5a09a5ee9974c4d02413e70fd363b7ad3 (patch)
tree13c8bb75aec300f66e3cd4c1cfc4369281ce8150
parentAdd references between stbl.1 and stws.1 (diff)
downloaddotfiles-080bd0e5a09a5ee9974c4d02413e70fd363b7ad3.tar.gz
dotfiles-080bd0e5a09a5ee9974c4d02413e70fd363b7ad3.zip
Add d2u(1) and u2d(1)
-rw-r--r--README.markdown3
-rw-r--r--bin/d2u9
-rw-r--r--bin/u2d10
-rw-r--r--man/man1/d2u.113
-rw-r--r--man/man1/u2d.113
5 files changed, 48 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown
index e8efad5f..a9e411fd 100644
--- a/README.markdown
+++ b/README.markdown
@@ -309,6 +309,9 @@ Installed by the `install-bin` target:
* `rnda(1)` uses `rndi(1)` to choose a random argument
* `rndf(1)` uses `rnda(1)` to choose a random file from a directory
* `rndl(1)` uses `rndi(1)` to choose a random line from files
+* Two file formatting scripts:
+ * `d2u(1)` converts DOS line endings in files to UNIX ones
+ * `u2d(1)` converts UNIX line endings in files to DOS ones
* `apf(1)` prepends arguments to a command with ones read from a file,
intended as a framework for shell functions.
* `ax(1)` evaluates an awk expression given on the command line; this is
diff --git a/bin/d2u b/bin/d2u
new file mode 100644
index 00000000..81700e15
--- /dev/null
+++ b/bin/d2u
@@ -0,0 +1,9 @@
+#!/bin/sh
+r=$(printf '\r')
+for fn ; do
+ ed -s -- "$fn" <<EOF || ex=1
+g/$r\$/ s/$r\$//
+w
+EOF
+done
+exit "${ex:-0}"
diff --git a/bin/u2d b/bin/u2d
new file mode 100644
index 00000000..5b4a96b6
--- /dev/null
+++ b/bin/u2d
@@ -0,0 +1,10 @@
+#!/bin/sh
+r=$(printf '\r')
+for fn ; do
+ ed -s -- "$fn" <<EOF || ex=1
+g/[^$r]\$/ s/\$/$r/
+g/^\$/ s/\$/$r/
+w
+EOF
+done
+exit "${ex:-0}"
diff --git a/man/man1/d2u.1 b/man/man1/d2u.1
new file mode 100644
index 00000000..33e07cb5
--- /dev/null
+++ b/man/man1/d2u.1
@@ -0,0 +1,13 @@
+.TH D2U 1 "August 2016" "Manual page for d2u"
+.SH NAME
+.B d2u
+\- change text files from DOS to UNIX format
+.SH USAGE
+.B d2u FILE1 [FILE2 ...]
+.SH DESCRIPTION
+Applies ed(1) to change DOS \\r\\n (CRLF) line endings to UNIX \\n line
+endings. Files already in UNIX format should be unchanged.
+.SH SEE ALSO
+ed(1), u2d(1)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/u2d.1 b/man/man1/u2d.1
new file mode 100644
index 00000000..48dfaeb5
--- /dev/null
+++ b/man/man1/u2d.1
@@ -0,0 +1,13 @@
+.TH U2D 1 "August 2016" "Manual page for u2d"
+.SH NAME
+.B u2d
+\- change text files from UNIX to DOS format
+.SH USAGE
+.B u2d FILE1 [FILE2 ...]
+.SH DESCRIPTION
+Applies ed(1) to change UNIX \\n line endings to DOS \\r\\n (CRLF) line
+endings. Files already in DOS format should be unchanged.
+.SH SEE ALSO
+ed(1), d2u(1)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>