Tag Info

New answers tagged

4

What is difference between | and <<()? There is a difference between them: | cause each command run in a separated subshell. <() run the command, which is substituted in background. For the next two question, we will do some strace: pipe: $ strace -fc bash -c 'tac /usr/share/dict/american-english | grep qwerty' $ time seconds ...


10

The construction <(tac file) causes to shell to: Create a pipe with a name On systems such as Linux and SysV which have /dev/fd, a regular pipe is used, and /dev/fd/<the-file-descriptor-of-the-pipe> is used as the name. On other systems, a named pipe is used, which requires creating an actual file entry on disk. Launch the command tac file and ...


7

If the file is really big, can not fit in memory, I will use Perl with File::ReadBackwards module from CPAN: $ cat reverse-grep.pl #!/usr/bin/perl use strict; use warnings; use File::ReadBackwards; ...


7

This one exits as soon as it finds the first match: tac hugeproduction.log | grep -m1 WhatImLookingFor The following gives the 5 lines before and after the first two matches: tac hugeproduction.log | grep -m2 -A 5 -B 5 WhatImLookingFor Remember not to use -i (case insensitive) unless you have to as that will slow down the grep. If you know the exact ...


30

tac/grep Solution tac file | grep whatever Or a bit more effective: grep whatever < <(tac file) Time with a 500MB file: real 0m1.225s user 0m1.164s sys 0m0.516s sed/grep Solution: sed '1!G;h;$!d' | grep whatever Time with a 500MB file: Aborted after 10+ minutes. awk/grep Solution: awk '{x[NR]=$0}END{while (NR) print x[NR--]}' ...


13

This solution might help: tac file_name | grep -e expression



Top 50 recent answers are included