Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

perl pattern matching

If grep pattern matching isn't behaving the way I expect, I turn to perl. While Perl, like awk, is a fully functional programming language, Here's how to invoke regex pattern matching from a command line using perl:

perl -n -e 'print $_ if $_=~/<pattern>/'

sed pattern substitution

The sed (string editor) command can be used to edit text using pattern substitution.

sed 's/<search pattern>/<replacement>/'

While sed is very powerful, the regex syntax for its more advanced features is quite different from "standard" grep or perl regular expressions. As a result, I tend to use it only for very simple substitutions, usually as a component of a multi-pipe expression.

perl pattern substitution

If I have a more complicated pattern, or if sed pattern substitution is not working as I expect (which happens frequently!), I again turn to perl. Here's how to invoke perl pattern substitution from a command line:

perl -p -e '~s/<search pattern>/<replacement>/'

Parentheses ( ) around one or more text sections in the <search pattern> will cause matching text to be captured in built-in perl variables $1, $2, etc., following the order of the parenthesized text. The capture variables can then be used in the <replacement>.

Field delimiter summary

Be aware of the default field delimiter for the various bash utilities, and how to change them:

...

Examples:

ls -l ~/.bash_history

haiku.txtdescription

Image Modified

  • dash ( - ) in position one signifies this is a regular file
  • rw- for owner allows read and write access
  • r-- for group permits only read access
  • --- for everyone means no access allowed

ls -l /usr/bin/ls

/usr/bin/ls
description

Image Modified

  • /usr/bin/ls is the program that performs the ls command
    • root (the master admin account) is the owner, in the root group
  • dash ( - ) in position one signifies this is a regular file
  • rwx for owner allows read, write and execute
  • r-x for group permits read and execute
  • r-x for everyone permits read and execute

ls -l -d ~/local (-d says to list directory information, not directory contents)

docs
description

Image Modified

  • d in position one signifies this is a directory
  • rwx for owner allows read, write and "execute" (list for directories)
  • r-x for group permits read and "execute" (list)
  • --- for everyone means no access allowed

Copying files between TACC and your laptop
Anchor
Copying_files_to_from_TACC
Copying_files_to_from_TACC

...