Earlier quoted context omitted.
From the man page cat doc1 doc2 > doc.all concatenates the files doc1 and doc2 and writes the result to doc.all
I think I'm missing your point. doc[12] aren't changed.
Unix Commands I Abuse Every Day
91–100 of 108 posts
Re: Unix Commands I Abuse Every Day
#92Earlier quoted context omitted.
I use xargs a lot for refactoring work when I cannot simply use sed, e.g. vim $(grep -lr foo | xargs) and doing what I need to do on a file by file basis. Otherwise, for renaming functions and the like, I do a lot of: find . -name foo_fn exec sed -i s/foo_fn/bar_fn/g '{}' \; I generally love abusing bash. Just today I was asked about how to rename a bunch of files, specifically containing spaces, and came up with eit…
Sorry, what do you think vim $(grep -lr foo | xargs) is doing? Assuming a missing directory after the `foo' why can't it just be vim $(grep -lr foo .) I don't see that xargs's default behaviour is adding anything. For find . -name foo_fn exec sed -i s/foo_fn/bar_fn/g '{}' \; you may find -exec's + of use. The above has the fork/execve overhead for each file found. find -name '*.[ch]' -exec sed -i 's/\ /bar/g' {} +
Thanks for the suggestion about -exec +; I will have to remember it in the future.
Re: Unix Commands I Abuse Every Day
#93My #1 abuse is xargs -n1. A lot of people like writing bash for loops, I will try and avoid that as much as possible, xargs -n1 is the bash equivalent of a call to 'map' in a functional language. For instance, let's say you want to create thumbnails of a bunch of jpegs: find images -name "*.jpg" | xargs -n1 -IF echo F F | sed -e 's/.jpg$/_thumb.jpg/' | xargs -n2 echo convert -geometry 200x Additionally, it's fully pa…
Why do that when a loop is clearer, safer, and shorter? find images -name '*.jpg' | while read jpg; do convert -geometry 200x "$jpg" "$(echo "$jpg" | sed 's/.jpg$/_thumb.jpg/')"; done This version works even when there are spaces in a filename, whereas yours will break.
find images -name "*.jpg" | while read -r jpg; do
convert -geometry 200x "$jpg" "${jpg%.jpg}_thumb.jpg"
done
This correctly handles spaces in file names and uses built in shell string replacement.Re: Unix Commands I Abuse Every Day
#94Earlier quoted context omitted.
Sorry, what do you think vim $(grep -lr foo | xargs) is doing? Assuming a missing directory after the `foo' why can't it just be vim $(grep -lr foo .) I don't see that xargs's default behaviour is adding anything. For find . -name foo_fn exec sed -i s/foo_fn/bar_fn/g '{}' \; you may find -exec's + of use. The above has the fork/execve overhead for each file found. find -name '*.[ch]' -exec sed -i 's/\ /bar/g' {} +
You are correct on both counts regarding the vim and grep example - I guess I just assumed I would have to have all the files on a single line before handing them off to vim. Thanks for the suggestion about -exec +; I will have to remember it in the future.
Re: Unix Commands I Abuse Every Day
#95I use the "grep with color for lines plus the empty string" so frequently that I have a function for it: function highlight() { local args=( "$@" ) for (( i=0; i This is only to be used as a filter, since it mangles filenames. I'm curious, does ack support a highlight-only mode?
Re: Unix Commands I Abuse Every Day
#96My #1 abuse is xargs -n1. A lot of people like writing bash for loops, I will try and avoid that as much as possible, xargs -n1 is the bash equivalent of a call to 'map' in a functional language. For instance, let's say you want to create thumbnails of a bunch of jpegs: find images -name "*.jpg" | xargs -n1 -IF echo F F | sed -e 's/.jpg$/_thumb.jpg/' | xargs -n2 echo convert -geometry 200x Additionally, it's fully pa…
Why do that when a loop is clearer, safer, and shorter? find images -name '*.jpg' | while read jpg; do convert -geometry 200x "$jpg" "$(echo "$jpg" | sed 's/.jpg$/_thumb.jpg/')"; done This version works even when there are spaces in a filename, whereas yours will break.
Re: Unix Commands I Abuse Every Day
#97Earlier quoted context omitted.
Do you remap ESC to another key?
No, but for me acts like and the actual keybinding is M-. or M-_. The command you are looking for is yank-last-arg for bash and insert-last-word for zsh.
Re: Unix Commands I Abuse Every Day
#98 foo | echoin bar
This is like `foo | bar`, but I can see what's passing between them. It's a bit like `tee`, but reversed. It's what I irrationally want `foo | tee - | bar` to do. my $args = join ' ', @ARGV;
open OUT, "|$args" or die "Can't run $args: $!\n";
while () {
print $_;
print OUT $_;
}Re: Unix Commands I Abuse Every Day
#99Earlier quoted context omitted.
I've sometimes heard it's "catenate" not "concatenate". Do they mean the same thing? As for cat, the utility, I'm afraid we'll never stop seeing people doing cat file|prog1|prog2 even when it makes absolutely no sense whatsoever. If it did, I might as well do cat file|cat|prog|cat|prog2|cat - I mean, why not? It "looks nicer" than prog file|prog2 or prog Programmers love their cats.
It's most definitely catenate. I understand catenate to mean chain and concatenate to be to chain together. Since "cat foo bar xyzzy" doesn't modify the files to join them in any way I don't think they're chained together. Besides, ken & Co. aren't daft. con would be short for concatenate. :-)
See: http://man.cat-v.org/unix-1st/1/cat http://man.cat-v.org/unix-6th/1/cat
I'm pretty sure based on the timeline of pipe (~1973, roughly V4) that the cat command (~1971 V1) predates pipes.
Re: Unix Commands I Abuse Every Day
#100Earlier quoted context omitted.
find ./ -name '*.log' -print0 | xargs -0 rm Fixes that issue and xargs is far more efficient, it doesn't launch a new process for each line like exec does, but far more importantly, xargs is generalizable to all commands so you only have to learn it once; exec is just an ugly hack on find, you can't generalize it across all commands; xargs is much more unixy.
Wanting to remove the files was so common that some finds have it built-in. Avoids even the overhead of -exec rm {} +. find -name '*.log' -delete