| Bytes | Lang | Time | Link |
|---|---|---|---|
| 002 | Jalapeño | 250306T212226Z | ATaco |
| 093 | Tcl | 180602T151114Z | sergiol |
| 052 | Ruby | 140127T180324Z | daniero |
| 003 | Japt | 210806T115639Z | Shaggy |
| 006 | Vyxal | 210805T100637Z | emanresu |
| 021 | Burlesque | 181125T133417Z | mroman |
| 033 | K4 | 181125T112348Z | mkst |
| 007 | Retina | 180426T204200Z | mbomb007 |
| nan | 140122T191738Z | FireFly | |
| 043 | PowerShell 43 | 140127T162317Z | microbia |
| 092 | Brainfuck | 140126T005344Z | Sylweste |
| 388 | iX3 | 140123T171258Z | Timtech |
| nan | 140122T192232Z | Oberon | |
| nan | 140122T184348Z | amon |
Jalapeño, 2 bytes
∩¢₁
Also ignores file IO requirements.
Simply takes the intersect ∩ of the input and all printable ascii ¢₁ and implicitly returns.
Hex-Dump of Bytecode
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000: ef 28
Tcl, 93 bytes
puts -nonewline [set g [open b.txt w]] [regsub -all {[^ -~]} [read [open a.txt]] ""]
close $g
Ruby (52)
Challenge #1
IO.write (f="a.txt"),IO.read(f).gsub(/\p{Cntrl}/,'')
Japt, 3 bytes
Well, seeing as everyone else is ignoring the requirements to read from & write to a file ...
Input also from this SO answer.
;oE
Japt v2.0a0, 3 bytes
r\P
Vyxal, 6 bytes
kPs5ȯ↔
Fixed thanks to Aaron Miller. Why does the printable ascii builtin contain unprintables?
Burlesque - 21 bytes
{**{31.>}{127.<}m&}f[
This can be shortened be replacing the 128 with '<DEL> (where DEL is the delete character) but I'm not sure how I can post a DEL here (also replace the 31 and then you can also get rid of the **)).
Also, in the WIP version you can golf this down to :un:ln.
K4, 36 33 bytes
Solution:
`b.txt 1:{x@&31<x*127>x}@1:`a.txt
Explanation:
Above is for Challenge A, replace the b.txt for a.txt for Challenge B.
`b.txt 1:{x@&31<x*127>x}@1:`a.txt / the solution
1:`a.txt / binary read (1:) "a.txt"
@ / apply to
{ } / lambda taking 1 implicit arg (x)
127>x / 127 greater than?
* / multiply by
x / x
31< / 31 less than?
& / indices where true
x@ / index into x at these indices
`b.txt 1: / binary write to "b.txt"
Retina, 7 bytes
Simple regex to remove non-printable ASCII.
[^ -~]
Test input copied from this SO post.
sh
Challenge 1, 24 23 chars
tr -dc \ -~<a.txt>b.txt
Bonus: variations on the set of characters to delete.
tr -dc " -~
"<a.txt>b.txt # preserves printables + line feed
tr -dc "[:space:] -~"<a.txt>b.txt # preserves printables + whitespace
PowerShell (43, 43)
Challenge 1: (43)
(gc -raw a.txt) -replace"[^ -x7e]","">b.txt
Challenge 2: (43)
(gc -raw a.txt) -replace"[^ -x7e]","">a.txt
Brainfuck: 92
+[[->+>+<<]>>>++++++++[->++++++++++++<<---->]>--[<<[->]>[<]>-]<+<[[-]>-<]>[[-]<<.>>]<<[-]<,]
Brainfuck cannot open files so you use stdin/stdout redirection (#1)
bf strip.bf < a.txt > b.txt
The same code in Extended Brainfuck: 68
+[(->+>+)3>8+(->12+<<4-)>2-[<<[->]>[<]>-]<+<([-]>-)>([-]2<.)2<[-]<,]
iX3, 388
Set in [c]: '1'
Loop start ([c] of 1 to 999999999)
Read from file 'a.txt' into [T] (read from [c], 1 bytes)
Modify text '[T]' into [R] (code in Hex)
Set in [N]: '&H[R]' (calculate)
If True: '([N]=10)'
Write into file 'b.txt' line '' (Append)
End If
If True: '([N]>31)&([N]<127)'
Write into file 'b.txt' line '[T]' (Append, no linefeed)
End If
Loop end
Both are Challenge 1.
C - 132 characters
#include<stdio.h>
k;main(){FILE*f=fopen("a.txt","rb");FILE*g=fopen("b.txt","w");while(!feof(f))(k=getc(f))>31&&k<127&&putc(k,g);}
Python - 78 characters
file("b.txt","w").write(filter(lambda x:'~'>=x>' ',file("a.txt").read()))
Bash + Perl
Challenge 1 – 31 bytes
perl -petr/\ -~//cd a.txt>b.txt
Challenge 2 – 28 bytes
perl -i -petr/\ -~//cd a.txt