Just wrote this because I'm wanting to convert numerous uppercase
variables in lots of shell programs to lowercase, except the initial
letter of a word. Manually, doing this would take forever.
First, however, I need to compile a list of variable names so I know
for what I want to search and replace, then omit certain ones typically
named in all uppercase, like `UID`, `USER`, `HOSTNAME`, etc, which I
will probably do by parsing `env` and various other special parameters
used by Bash.
Fun times.
Many uses for this!
Say you install a large set of updates, so want to cross-check the old
list to the new one, in order to find out which new executables were
installed.
Or, perhaps less obscure, you might this list, without the `-printf`
part, to check their permission and ownership settings.
The examples given using xargs are so far mostly never or rarely ever
best used or even well used with xargs, such as with find, which is
popular, unfortunately.
My reason for adding counters to some of these examples, is that, as an
educational resource, I believe it's important users understand what is
and is _not_ good practice; this is, at least, how I taught myself.
The `-i` flag with `sed` means "in-place", if you're curious; the use
thereof allows for making actual changes to the file, not just
superfluously, such as for additional parsing.
The `s///` is a simple substitution, wherein the `s` marks that it's a
substitution, the `/` marks the boundaries*, and the final boundary can
be suffixed with various flags, such as `g`, for global operations, -
and `i`, for case-insensitive operations.
* required, but the slash can switched for something else, if needed, -
such as `|`, which is commonly used for paths. For example:
`s|/path/to/file|/path/file|`
The for loop was problematic for numerous reasons my headache won't
allow me to list. I've optimized it, while hoping to maintain the point
for which it was submitted.
A couple of typos were fixed; nothing major.
This was taken from my own notes amassed over several years. Commands
like these are a real time-saver.
A lot of people, I imagine, will probably use `-exec rm {} \+` which is
fine and all, but it's another process you'd have to launch, which
isn't necessary at all, unless you need certain `rm` functionality.
This is useful, but not if this is _all_ you're after; in those
cases, you're better off just using `free | wc -l` or similar.
However, there may be times you need to count the number of lines in
order to achieve _other_ things programmed in awk, which would then be
crucial!
For example, you may wish to output text informing the user of how many
log entries were discovered in one or more files given to awk.
ENVIRON is a special associative array variable, and LS_COLORS is an
index therein. If you want to see the available variables you could
use, you could execute the trusty `env` command.
This is useful for those times you want to just do something in awk, -
on-the-fly, without having to rely on its standard input (STDIN).
It's especially handy when you want to perform floating-point
arithmetic, if you're not a shell like ZSH which does support it.