Coder Social home page Coder Social logo

catgolf's Introduction

cat(1) golf

Get the file to stdout as intact as possible.

Pure league

  • No shell features are involved.
  • Only outputs to stdout.
cat file.txt
awk 1 file.txt
paste file.txt
pv -q file.txt
pr -t file.txt
sed b file.txt
grep ^ file.txt
grep $ file.txt
sed '' file.txt
grep '' file.txt
sort -m file.txt
look '' file.txt
jq -rR . file.txt
sed -n p file.txt
cut -b 1- file.txt
jq -jRs . file.txt
perl -pe1 file.txt
tail -n +1 file.txt
head -n -0 file.txt # GNU head
cp file.txt /dev/fd/1
gcc -E -P -xc file.txt
scp file.txt /dev/fd/1
column -t -l 1 file.txt
comm file.txt /dev/null # BSD comm
w3m -dump_source file.txt
dd status=none if=file.txt # GNU dd
hexdump -ve '"%c"' file.txt
split --filter=tee file.txt # GNU split
join -a 1 file.txt /dev/null
openssl enc -none -in file.txt
curl file:///proc/self/cwd/file.txt
git -P grep --no-index -h ^ file.txt
shuf --random-source=/dev/zero file.txt
bat --color=never --style=plain file.txt
diff --line-format=%L /dev/null file.txt
vim -es --clean '+w! /dev/fd/1' '+q!' file.txt
python -c 'print(open("file.txt").read()[:-1])'
ffmpeg -v quiet -f data -i file.txt -map 0:0 -c text -f data -
emacs -Q --batch --eval '(princ (with-temp-buffer (insert-file-contents "file.txt") (buffer-string)))'

Shell league league

  • Can use shell feature like pipes, redirect etc to work.
tee < file.txt
tr a a < file.txt
rev file.txt | rev
tac file.txt | tac
echo ',p' | ed -s file.txt
xxd -p file.txt | xxd -p -r

Brittle league

  • May not handle every character.
  • May not handle every file length.
sed '/*/p' file.txt
gcc -E -P -xc file.txt

Error league

  • Same as "Pure league", but errors on stdout and/or stderr are acceptable.
dd if=file.txt
gcc -xc file.txt

Junk league

  • Same as "Error league", but most of the output bytes are from the file.
m4 file.txt # Does not handle lines that starts with `#` or looks like definitions.
fold file.txt # Works for files without long lines
wall -n file.txt # I hope your file doesn't have any secrets
uniq -Dw0 file.txt # Doesn't work for single-line files
xargs -d\n -a a.txt echo # Ends up with a trailing newline
more -e -n 65535 file.txt # Works for files with less than 65k lines.
nl -bn -w 1 -s '' file.txt # Each line has an extra space

catgolf's People

Contributors

alokmenghrajani avatar andoma avatar benhoyt avatar emanuele6 avatar itchyny avatar jaanvaks avatar jwilk avatar kotborealis avatar magisterquis avatar qbit avatar tomska-pfsw avatar wader avatar xyproto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

catgolf's Issues

Broken sed '/*/p'

In #1, @Doctor-love added

sed '/*/p' file.txt

But this duplicates lines containing the * character. E.g.:

$ printf '*hello*\nworld!\n' > file.txt
$ cat file.txt
*hello*
world!
$ sed '/*/p' file.txt
*hello*
*hello*
world!

There's now another sed call that is shorter and works correctly, so IMHO this one should be removed.

Clarify rules

The rules are a bit unclear to me. Are non-pipe sequences of two commands allowed (as in foo file.txt; bar)? If so, I have one.

Broken gcc

In #9, @kotborealis added a gcc command, but this doesn't quite work with arbitrary files.
For example:

$ cat README.md | wc -l
44

$ gcc -E -P -xc README.md | wc -l
README.md:1:3: error: invalid preprocessing directive #cat
    1 | # cat(1) golf
      |   ^~~
35

While it's an interesting hack, I don't think it belongs in the "Pure league".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.