g | x | w | all
Bytes Lang Time Link
045AWK250826T193559Zxrs
003Vyxal210430T002745Zlyxal
065Julia 1.x210705T152219ZMarcMush
005Japt210705T114658ZShaggy
089Go210704T232537ZZombo
00405AB1E210429T173319ZMakonede
179S.I.L.O.S160827T133845ZRohan Jh
198Java160725T215912Zuser8397
133Haskell151001T015606ZKevin Re
014sed151001T002404ZÁng
097Python 2150929T184713Zjqkul
226C#151002T081334ZRobIII
342C#150930T205225Zundersco
292CoffeeScript150930T093557Zdunpeal6
018CJam150930T005541ZDennis
108C151001T025919Zalgmyr
066Mathematica151001T025303ZVerbeia
006Perl150929T192550Zsteve
097R150930T082751Zplannapu
123Python 3150929T182040Zmatsjoyc
053Python 2150929T193530ZAnders K
077Python 3150929T191936ZAnders K
112PowerShell150929T185603ZAdmBorkB
013Ruby150929T175735Zdaniero
123Julia150929T175504ZAlex A.
011Perl150929T173424ZJarmex
019Bash150929T170003ZDennis

AWK, 45 bytes

{for(i=0;i++<NF;)$i~/[A-Z]/&&$i=tolower($i)}1

Attempt This Online!

This is what I want to use, but it swaps unicode chars as well:

$0=tolower($0)

Vyxal, 24 bitsv1, 3 bytes

kAnĿ

Try it Online!

The power of context variable overloads and range coding! Simply transliterate the uppercase alphabet to the lowercase alphabet.

Julia 1.x, 65 bytes

!s=print.(c+32('@'<c<'[') for c=read(s,String))
.!ARGS>[]||!stdin

Try it online! (stdin)

Try it online! (files)

Japt, 5 bytes

;dBíC

Try it

Japt v2.0a0, 5 bytes

r\A_v

Try it

Go, 89 bytes

package main
import(."fmt"
."strings")
func main(){s:=""
for{Scan(&s)
print(ToLower(s))}}

05AB1E, 4 bytes

AuA‡

Try it online! Beats all other answers.

AuA‡  # full program
   ‡  # replace all characters of...
A     # "abcdefghijklmnopqrstuvwxyz"...
 u    # in uppercase...
   ‡  # with corresponding character in...
  A   # "abcdefghijklmnopqrstuvwxyz"...
   ‡  # in...
      # implicit input
      # implicit output

S.I.L.O.S 179 characters

loadLine :
a = 256
x = get a
lbla
X = x
B = x
C = 91
B - 64
if B c
printChar x
GOTO x
lblc
C - x
if C D
printChar x
GOTO x
lblD
x + 32
printChar x
lblx
a + 1
x = get a
if x a
lblb

Feel free to try this code online!


Essentially it translates to this in pusedocode.

String input = input();
for(char c in input)
if(c is uppercase) print c + 32/*lowercase c*/else print c

Java, 198 bytes

b->B->{B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;};

You are forced to use the above lambda with files, so there's no need to take input from STDIN! Also, it's a Function<File[], UnaryOperator<String>>. It's used like foo.apply(anArrayOfFiles).apply(anything).

As something that makes more sense to those who are new to Java, it takes 223 bytes:

String A(java.io.File[]b){String B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;}

As something that compiles, it takes up 232 bytes:

class a{String A(java.io.File[]b){String B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;}}

Haskell, 133

import System.Environment
main=getArgs>>=mapM_(>>=putStr.map l).f
f[]=[getContents]
f n=map readFile n
l x=[x..]!!sum[32|x>'@',x<'[']

The cat-style args processing is derived from this tutorial, then rearranged to shave characters.

Explaining l, the function to lowercase one character:

Thanks to Anders Kaseorg for contributing the sum[...|...] and [x..]!! tricks.

sed, 14 bytes

s/[A-Z]/\L\0/g

Run with env -i sed -f kitten.sed.

Python 2, 100 102 97 bytes

Functionality corrected (and 4 bytes added) by matsjoyce. Fortunately, I saved two bytes by switching to Python 2.

from sys import*;print''.join(f.read().lower()for f in(map(open,argv[1:])if argv[1:]else[stdin]))

Takes arguments from the command line, or from STDIN if no arguments found.

This abuses the default arguments of some functions. By default, open uses read-only text mode, which is exactly what we want. read, if called with no arguments, will return all text in the stream.

Ungolfed:

import sys

if len(sys.argv) > 1:              # If we have command-line arguments:
    source = []                    # Initialize an empty list
    for path in sys.argv[1:]:      # Iterate through every filename we have
        kitfile = open(path, 'rt') # Open the file in read-only text mode
        source.append(kitfile)     # Add it to the list
else:                              # Otherwise, if the args are empty:
    source = [sys.stdin]           # Set our source to STDIN wrapped in a list

kittened = []                      # Initialize an empty list
for kitfile in source:             # Iterate through every file (or just STDIN)
    text = kitfile.read()          # Read everything from the stream
    kitten_text = text.lower()     # Make it lowercase
    kittened.append(kitten_text)   # Add it to the list
final = ''.join(kittened)          # Join everything together
print final                        # Print the result

C#, 230 226 bytes

namespace System{using Linq;class P{static void Main(string[]a){Console.Write(string.Concat((a.Length>0?string.Concat(a.Select(f=>IO.File.ReadAllText(f))):Console.In.ReadToEnd()).Select(c=>c>'@'&&c<'['?char.ToLower(c):c)));}}}

Ungolfed:

namespace System
{
    using Linq;
    class P
    {
        static void Main(string[] a)
        {
            Console.Write(                                                  // Print...
                string.Concat(                                                  // ...all chars combined to a string...
                    (a.Length > 0 ?                                             // ...commandline arguments?...
                        string.Concat(a.Select(f => IO.File.ReadAllText(f))) :  // ...then all files as single string...
                        Console.In.ReadToEnd()                                  // ...else STDIN input
                    ).Select(c => c > '@' && c < '[' ? char.ToLower(c) : c)     // ...Lowercase only A..Z
                )
            );  
        }
    }
}

C#, 342 bytes

namespace System{
using IO;
using Linq;
class P{
static void Main(string[]a){
Action<char>e=C=>{var c=char.ToLower(C);Console.Out.Write(c>='a'&&c<='z'?c:C);};
if(a.Length>0)a.ToList().ForEach(f=>File.ReadAllText(f).ToCharArray().ToList().ForEach(e));
else 
while(true) Console.In.ReadLine().ToCharArray().ToList().ForEach(e);
}
}
}

C#, 319 bytes

single-liner, same as above:

namespace System{using IO;using Linq;class P{static void Main(string[]a){Action<char>e=C=>{var c=char.ToLower(C);Console.Out.Write(c>='a'&&c<='z'?c:C);};if(a.Length>0)a.ToList().ForEach(f=>File.ReadAllText(f).ToCharArray().ToList().ForEach(e));else while(true)Console.In.ReadLine().ToCharArray().ToList().ForEach(e);}}}

CoffeeScript, 292 bytes

f=require 'fs';d='';p=process;v=p.argv;s=p.stdin;l=((d)=>console.log d.replace /([A-Z])/g,(a,l)=>l.toLowerCase());if v.length>2 then(v.forEach (v,i)=>if i>1 then(f.exists v, (e) =>if e then(f.readFile v,'utf-8',(r,d)=>l d) else l v))else(s.resume();(s.on 'data',(c)=>d+=c);s.on 'end',()=>l d)

Usage:

$ echo "HelLo" > file.txt
$ coffee kitten.coffee file.txt
hello
$ echo "Good Bye" | coffee kitten.coffee
good bye
$ echo "Ä" | kitten
Ä
$ coffee kitten.coffee file.txt SoMeTeXt
sometext
hello

My first participation on codegolf so please don't be rude :).

For sure this code can be golfed more and coffee/javascript isn't the best choice to do that, but it does what's expected.

When it reads arguments it also takes care about file existency (if file does not exists, the string is kittened.)

Any help or advice to improve this code is welcome !

CJam, 18 bytes

ea_:gs{q}?'_,_eler

The list of files must be supplied in form of URLs, which is the only format CJam understands.

Example runs

$ cjam kitten <<< "AaÁáÄä"
aaÁáÄä
$ cjam kitten file:///home/dennis/kitten file:///home/dennis/kitten
ea_:gs{q}?'_,_elerea_:gs{q}?'_,_eler

How it works

ea                  Push the array of command-line arguments.
  _                 Push a copy.
   :g               Retrieve the contents of all files with those URLS.
     s              Flatten the resulting array of strings.
      {q}           Push a block that reads all input from STDIN.
         ?          Select the string of the array of args is non-empty.
                    Otherwise, execute the code block.
          '_,       Push the string of all ASCII characters before _.
             _el    Push a copy and convert it to lowercase.
                er  Perform transliteration.

C, 106 108 bytes

Edit: Fixed a mistake that creeped in when squeezing bytes. Stdin wasn't working, now it is.

I'm pretty sure I could squeeze some bytes away, but here's an easy-to-grasp, not at all language abusive, submission:

main(n,s,f,c)void**s;{for(f=n-1?open(*++s,0,0):0;read(f,&c,1);putchar(64<c&c<91?c+32:c));n-->2&&main(n,s);}

And a somewhat more neatly formatted version for reading:

main(n,s,f,c)
void**s;
{
    for(f=n-1?open(*++s,0,0):0; read(f,&c,1); putchar(64<c&c<91?c+32:c));
    n-->2&&main(n,s);
}

Mathematica, 66 bytes

kit=StringReplace[#,x:RegularExpression["[A-Z]"]:>ToLowerCase[x]]&

Called as

kit@"HelLo"

Mathematica already has a ToLowerCase function, but it converts special (Unicode and mathematical) characters as well. So I had to kittenize it. This function will take any input.

Perl, 6 bytes

5 bytes code + 1 byte command line

$_=lc

Example usage:

echo ABCdef | perl -p kitten.pl
abcdef

Confirmation of correct Unicode behaviour:

echo "HelloÉ" | perl -p kitten.pl
helloÉ

R, 97 bytes

cat(chartr("A-Z","a-z",sapply(if(length(a<-commandArgs(T))){a}else{"stdin"},readLines)),sep="\n")

Usage:

$ echo "HeLlo" > file.txt
$ Rscript kitten.R file.txt
hello
$ echo "Good Bye" | Rscript kitten.R
good bye
$ echo "bLABLa" > file2.txt
$ Rscript kitten.R file.txt file2.txt
hello
blabla
$ echo Ä | Rscript kitten.R
Ä

Python 3, 124 123 bytes


from sys import*
for f in list(map(open,argv[1:]))or[stdin]:print(f.read().translate({i:i+32for i in range(65,91)}),end="")

Python eats kittens!

$ python kitten.py file.txt
hello
$ echo "Good Bye" | python kitten.py 
good bye
$ echo "Ä" | python kitten.py 
Ä

Python 2, 53 bytes

from fileinput import*
print''.join(input()).lower(),

Python 3, 77 bytes

from fileinput import*
print(end=b''.join(input(mode='rb')).lower().decode())

PowerShell, 112 Bytes

function l([string]$a){97..122|%{[char]$b=$_;$a=$a-split$b-join$b};$a}if($args){$args|%{l(gc $_)}}else{l $input}

Horrendously unreadable. Here's a slightly expanded version below:

function l([string]$a){
  97..122|%{
    [char]$b=$_
    $a=$a-split$b-join$b
  }
  $a
}

if($args){
  $args|%{
    l(gc $_)
  }
}
else{
  l $input
}

Defines an internal function l which iterates over a loop from 97 to 112 (i.e., ASCII a to ASCII z). Splits the input string over that character (yay case-insensitive default), the rejoins it with the "correct" lower case. Do note that yes, this means "Test" would briefly become "T st" as it's iterating through the e, for example. Doesn't affect output.

The second half is the tricky bit to figure out if we have pipeline input (equivalent to stdin for PowerShell) or command-line input. The special variable $args is only present if command-line input is present, so we loop over each one, gc (for Get-Content) and schlep that up to l. Otherwise, we just schlep our $input up to l. Note that we could swap our if/else statements (i.e., if($input)), but since "input" is one character longer than "args" this way is shorter.

Ruby, 13 bytes

The byte count includes 1 byte for the p flag. Run it like so: ruby -p kitten.rb.

$_.downcase!

Takes input from stdin or file arguments, just like grown up cat.

Julia, 123 bytes

f(s)=for l=readlines(s) print(replace(l,r"[A-Z]",lowercase))end
A=ARGS
length(A)>0?for i=A open(f,i)end:open(f,readline())

Ungolfed:

function file_to_lower(s::Stream)
    # Loop over the lines of the input stream
    for l in readlines(r)
        # Print the lowercased line
        print(replace(l, r"[A-Z]", lowercase))
    end
end

if length(ARGS) > 0
    # Loop over the files specified from the command line
    for i in ARGS
        # Open the file, apply the function, then close it
        open(file_to_lower, i)
    end
else
    # Get the input file from STDIN
    open(file_to_lower, readline())
end

Perl, 11 bytes

10 bytes code + 1 byte command line

y/A-Z/a-z/

Example usage:

perl -p entry.pl input1.txt input2.txt
echo "ABCdef" | perl -p entry.pl

Bash, 19 bytes

cat "$@"|tr A-Z a-z

The best way to make kittens is to use actual cats.

Example run

$ ./kitten kitten
cat "$@"|tr a-z a-z