{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Text and arithmetic in `bash`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Working with text streams\n", " - `stdin`, `stdout`, `sterr`\n", " - `>`, `>>`, `<`\n", " - `|`\n", " - `echo`\n", " - `cat`\n", " - `HEREDOCS`\n", " - `printf`\n", " - `cut`\n", " - `sort`\n", " - `uniq`\n", " - brace expansions" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "echo 'Hello' > foo.txt" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "echo 'Goodbye' >> foo.txt" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello\n", "Goodbye\n" ] } ], "source": [ "cat foo.txt" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello\n", "Goodbye\n" ] } ], "source": [ "cat foo.txt" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello\n", "Goodbye\n" ] } ], "source": [ "cat < foo.txt" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cat > bar.txt < bar.txt < big.txt" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "One\n", "Two\n", "Three\n", "Hello\n", "Goodbye\n" ] } ], "source": [ "cat big.txt" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "One\n", "Two\n", "Three\n" ] } ], "source": [ "cat big.txt | sed 4,6d" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "One\n", "Two\n", "Three\n", "Hello\n", "Goodbye\n" ] } ], "source": [ "cat big.txt | sed /'^ '/d" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sed: 1: \"/o/Ip\": invalid command code I\n" ] }, { "ename": "", "evalue": "1", "output_type": "error", "traceback": [] } ], "source": [ "cat big.txt | sed -n /'o'/Ip" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cat > humpty.txt <