by bee_rider · 2y ago · 0 comments
cat filename.txt
Up | grep “thing I want”
Is fewer keystrokes than cat filename.txt
grep “thing I want” filename.txt
Or more likely cat filename.txt
grep filename.txt “thing I want”
grep “thing I want” filename.txt grep “thing I want” !$
Bash (and similar) will replace !$ with the last parameter of the previous command.This is a trick I’ve used lots when wanting to perform a non-piping operation on a command I’ve ‘cat’ed (eg ‘rm -v !$’)
I’d never criticise anyone for “useless” use of ‘cat’ though. If the fork() overhead was really that critical then it wouldn’t be a shell command to begin with.
bind '"\e."':yank-last-arg
So [esc] _ does it on systems where I haven't customised my environment. A major drawback though is it doesn't go through history like alt . does.However, when 'set -o vi' is enabled you can easily go through history and edit with familiar vi keystrokes, or press 'fc' and fix the previous command in EDITOR, or 'v' to edit the current command in EDITOR.
I think you meant 'vv' and I wonder if it's not something that's set up by oh-my-zsh ? It's great though
Press Escape, then the number of the argument from the previous command, confirm with Ctrl+Alt+Y.
Example:
> command arg1 arg2 arg3
Escape, 1, Ctrl+Alt+Y gives you arg1. cat filename.txt
grep "what I want" $_
expands "$_" to "filename.txt"Then I can look at it before hitting return
useful shorthand
> sudo !!
for example.
Again, bash specific.
$ cat file
$ grep stuff alt-.
Alternatively, make use off the READNULLCMD mechanism in Zsh: $ < file
translates to $ ${READNULLCMD:-more} < file
Thus you can $ < file
then UP (or ctrl-p which I find more ergonomic) and continue with "grep stuff": $ < file grep stuff
(Redirections can be anywhere in the command.)https://zsh.sourceforge.io/Doc/Release/Redirection.html#Redi...
cat log | not spam1 | not spam2 | not 'spam(3|4)' | .... | less alias -g V='| grep -vE'
alias -g L="| $PAGER"
Then you can do cat log V spam1 V spam2 L
I also like alias -g G='| grep'
alias -g X='| xargs'
The possibilities are endless...UUoC criticism, to me, belongs when one sits down to script.
cat “filename.txt”
Up | grep “thing”
Up | grep -v “not thing”
Up | grep -v “other thing”
Etc. it’s just easier to build this way even if the initial cat is unnecessary.
> grep “thing I want” filename.txt.
…every time
< file.txt grep pattern
Less keystrokes. < file.txt cat
But then one has to ctrl-w cat. It is a pity that this is not an alternative to cat for a single file: < file.txt