Ondřej Plátek Blog
PhD candidate@UFAL, Prague. LLM & TTS evaluation. Engineer. Researcher. Speaker. Father.

Week 6, Intro to Unix lab 2016

Content

  • Recap homework
    • rev - GNU specific
    • bc, cut -c
    • sed 's/(.*)([0-9]*) ([a-zA-Z]*)/\3 \2\1/'
    • printf
    • run commands in batch after you ssh to remote computer e.g.
      • ssh login@computer 'your_first_command; your_other | piped_command'
    • grep -E does not use basic regular expressions;-)
      • What are the differences?
  • Recap
    • join, tee, tail, pwd, pg, less, more, head, chmod, chown, tr, cut, wc, strings, cat
  • presentation/todos - diff, comm, paste, split
  • sed regexp continuation
  • Additional program flow commands
    • while, read, if

Homework

  • (1 point) Write a script nl_4digits.sh which uses a while and read commands to reading a standard input and inserting a number at the beginning of line together with a double colon.
# Example input:
Hi Jack,
how are you?
# Example output:
0001: Hi Jack,
0002: how are you?
  • (1 point) Write a script palindrome.sh [argument] which takes as argument either file name or -.
    • If filename is provided it process lines from file. If - is provided it process lines from stdin.
    • For each line it decides whether it is a palindrome. If it is not palindrome it skips the line otherwise it prints the palindrome to standard output.
  • (1 point) Write a script evener.sh which keeps only even lines in the input file
    • hints: seq, seq -n, sed 'command1;command2;command3' file
# Example
$ seq 11 > test_input
$ evener.sh test_input
$ cat test_input
2
4
6
8
10

Bonus

  • (1 point) Prepare presentation on command comm