INFO 1211

Cards (29)

  • In Linux commands and regular expressions, ^$ together represent a pattern that matches empty lines, i.e., lines with no characters, including no whitespace characters
  • Symbols Meaning:
    • ^ matches the start of a line
    • $ matches the end of a line
    • ^$ combined means a line that starts immediately and ends immediately, indicative of an empty line
  • `^` matches the start of a line
  • `$` matches the end of a line
  • When combined, `^$` indicates an empty line that starts and ends immediately
  • In regular expressions, the dollar sign `$` is used to indicate a variable in command lines or scripts
  • In regular expressions, `$` matches the end of a line
  • The pattern `foo$` would match lines ending with "foo"
  • In regular expressions, the caret `^` matches the start of a line
  • The pattern `^bar` would match lines starting with "bar"
  • The `sed` command with `-n '1,2p'` displays the first and second lines of the file `dukeofyork.txt`
  • The `sed` command with `-n '/down/p'` displays lines containing the word "down" in the file `dukeofyork.txt`
  • The `nl` command numbers the lines in the file `dukeofyork.txt`
  • The `nl` command with `| sed '1d;3d'` removes the first and third lines from the numbered output
  • The `nl` command with `| sed '2,4d'` removes lines 2 to 4 from the numbered output
  • The `nl` command with `-n '2, 4 p'` displays lines 2 to 4 from the numbered output
  • The `nl` command with `-n '2, 4 !p'` displays lines that are not 2 to 4 from the numbered output
  • The `nl` command with `-n '/down/, /they/ p'` displays lines between "down" and "they" from the numbered output
  • The `nl` command with `| sed '/down/, /they/ d'` removes lines between "down" and "they" from the numbered output
  • The `sed` command with `'/^.a/p' input_file` prints lines containing a word where the second letter is "a" in the `input_file`
  • The `date` command displays the date and time in UTC
  • The `date | cut -c12-16` command extracts the time from the output of the `date` command
  • The `cut` command with `c12-16` specifies the range of characters to extract, which is the time
  • The `sed 's/\([Uu]nix\)/\1(TM)/g' intro > text.out` command adds "(TM)" to occurrences of "Unix" or "unix" in the `intro` text file and overwrites `text.out` with the edited content
  • The `awk -F: '/true?man/ {printf("%-20s %-12s %6d\n", $2, $3, $6) }' emp.lst` command separates lines into fields with ":" as the delimiter and prints specific fields based on the pattern "true?man" in the `emp.lst` file
  • The `awk -F: '/sales/ { print $1, $2, $3 }' emp.lst` command separates lines into fields with ":" as the delimiter and prints specific fields from lines containing "sales" in the `emp.lst` file
  • The `awk ‘/^$/’ emp.lst` command searches for empty lines in the `emp.lst` file
  • The `awk ‘/wilco[cx]k*s*|wood(cock|house)/’ emp.lst` command searches for patterns "wilcock", "wilcox", "woodcock", or "woodhouse" in the `emp.lst` file
  • Capturing groups, denoted by `\(` and `\)` in regular expressions, serve several useful purposes: