commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
There are 11 alternatives - vote for the best!
I find this terribly useful for grepping through a file, looking for just a block of text. There's "grep -A # pattern file.txt" to see a specific number of lines following your pattern, but what if you want to see the whole block? Say, the output of "dmidecode" (as root):
dmidecode | awk '/Battery/,/^$/'
Will show me everything following the battery block up to the next block of text. Again, I find this extremely useful when I want to see whole blocks of text based on a pattern, and I don't care to see the rest of the data in output. This could be used against the '/etc/securetty/user' file on Unix to find the block of a specific user. It could be used against VirtualHosts or Directories on Apache to find specific definitions. The scenarios go on for any text formatted in a block fashion. Very handy.
By using vim, you can also filter content on stdout, using vim's extra power, like search pattern offset!
No more awk of course, sorry.
-e ex mode
-c 'ex command' : global + start and end pattern + offset print (p)
-cq : quit
If you can do better, submit your command here.
You must be signed in to comment.