sort order.*
is surely more elegant than cat order.* | sort
which is fair enough, however, as it happens, i generally do end up using 'cat' in the way he's used it.. for such small jobs nobody can be genuinely worried about the overhead, and it comes down to a matter of taste..personally, i find that using 'cat output | $command' helps to separate out the 'logic' of what i'm doing, if that makes sense..
also, again, purely as a matter of taste
i'd prefer
egrep 'Hardcover|Kindle'
over grep "\(Kindle\|Hardcover\)"
EDIT: (as alexfoo has pointed out, this isn't a proper AND as it worries about the order.. my bad, still useful though :D )and as a sidenote, something i only found recently, but which is quite useful, a logical AND with egrep looks like
egrep 'Hardcover.*Kindle'> and as a sidenote, something i only found recently, but which is quite useful, a logical AND with egrep looks like > > egrep 'Hardcover.Kindle'
That's not a true logical AND since it won't pick up an entry with the text "Kindle Hardcover". Only entries with the word "Hardcover" eventually followed by "Kindle". To cover both cases you'd need:-
egrep 'Hardcover.*Kindle|Kindle.*Hardcover'
(Of course, someone will now show how this can be done in even fewer characters).awk doesn't have to be complicated ;)
<foo sort | ...
is an alternative to cat foo | sort | ...
though I wouldn't particularly recommend it. Instead the overhead of cat(1) should be omitted and it written in the normally accepted form of sort foo | ...
Providing a filename rather than re-directing stdin allows the program more choice over its method of access.While iterating on a command line, it keeps things uniform, rather than switching between "sort foo" and "tai64nlocal < foo" and "ffmpeg -i foo", by which I mean: different programs take their input in different ways. You can normalize by making each take standard input, and feed the chain with a "cat".
However, things change if you start adding certain options to sort:-
sort -m order.*
and cat order.* | sort -m
are definitely not the same thing (for most input files at least). > If the original title begins with a number or number + gratuitous
> adjective, we'd appreciate it if you'd crop it. E.g. translate
> "10 Ways To Do X" to "How To Do X," and "14 Amazing Ys" to "Ys."
> Exception: when the number is meaningful, e.g. "The 5 Platonic Solids."Say you have two files, one with lines of numbers:
1
2
3
... and one with letters: A
B
C
$ paste numbers letters 1 A
2 B
3 C
Want CSV?$ paste -d, numbers letters
1,A
2,B
3,C
Or, with '-s' you can join lines from inside the same file. For instance, you can sum numbers:$ paste -sd+ numbers
1+2+3
$ paste -sd+ numbers |bc 6
(Thanks to a Stack Overflow post somewhere for suggesting that one!)Useful example: the total resident memory size of all chromium processes:
$ ps --no-headers -o rss -C chromium | paste -sd+ | bc
793180 paste <(ping 8.8.8.8) <(while true; do iwconfig wlan0 | grep "Bit Rate"; sleep 1; done)What about some slightly less basic ones that I'd think would be useful for many people.
# less with syntax highlighting
alias less="/usr/share/vim/vimcurrent/macros/less.sh"
tailf # tail -f, but better & shorter
mtr # check your connection (ie., traceroute with more info)
htop # nice a colorful process listing (better than top)
locate # search files by name -- that late-night disk thrashing is useful after all!Since I wouldn't ever ask them to do something I wouldn't do myself, I send these reports too. This link will go in my miscellany section this week. I think it'll be useful, and I wouldn't have ever found it or even considered including something like it had it not shown up on HN.
That's better about tailf, and why would I use it instead of the (far superior to tail) less +F?
https://blogs.oracle.com/ksplice/entry/strace_the_sysadmin_s...
More from a sysadmin POV than a dev, but you'd probably still find it useful.
With the files in the example (order.out.log, order.in.log), to join every record on it's id, you would do something like:
$ join -j 2 order.out.log order.in.log
111, 8:22:19 1, Patterns of Enterprise Architecture, Kindle edition, 39.99 8:22:20 Order Complete
112, 8:23:45 1, Joy of Clojure, Hardcover, 29.99 8:23:50 Order sent to fulfillment
113, 8:24:19 -1, Patterns of Enterprise Architecture, Kindle edition, 39.99 8:24:20 Refund sent to processing"What are some time-saving tips that every Linux user should know?"
http://www.quora.com/Linux/What-are-some-time-saving-tips-th...
http://motd.ambians.com/quotes.php/name/linux_songs_poems/to...
I have found it to be surprisingly useful. Nobody uses all the commands but remembering that something like zcat exists can be extremely useful. Also remembering to pipe through sort before sending through uniq is helpful as well.
tail -F filename
as most of the logfiles I need to watch tend to wrap at some point and 'tail -f' doesn't check for inode changes.
(-F is a non-standard option, it's there on GNU's [EDIT] tail binary and OS-X but not Solaris for example).
one benefit to less +F is that you can cancel the following and read normally in less.
Yeah, including doing backwards and forward searches, that is very handy
8 Linux Commands Every Developer Should Know [for log analysis]
They are all generic unix commands.
grep -i 'pattern' file | awk '{print $5}' | sed 's/^/cmd/g'
I end up sending to a file, chmod, then run it at the shell.
$(grep -i 'pattern' file | awk '{print $5}' | sed 's/^/cmd/g')
?Or surround in backticks
`command which outputs text you want to run as a command`
I prefer $() as they nest better.Or have I misunderstood your question?
~$ help eval eval: eval [arg ...] Execute arguments as a shell command.
Combine ARGs into a single string, use the result as input to the shell,
and execute the resulting commands.
Exit Status:
Returns exit status of command or success if command is null.grep -i 'pattern' file | awk '{print $5}' | xargs cmd