Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Are you sure that all the files really show up in <code>cat *.txt &gt; out</code>? Unless you are right at the edge of the maximum number of characters per command, it should not make a difference. Try this:</p> <pre><code>ls -1 | egrep '\.txt$' | xargs egrep "" /dev/null &gt; out </code></pre> <p><code>ls -1</code> lists all the files in the directory, one file name per line, and the first <code>egrep</code> filters out just the ones ending in ".txt". This way, you don't have to worry about running out of command line length in listing the files. <code>xargs</code> reads <code>stdin</code>, until it gets as many lines as it can fit on a single command line after the other arguments to <code>xargs</code>. It then calls the command you provide with the options you provided with that set of input parameters. <code>xargs</code> then repeats that process until it uses up all the arguments you provide. Each invocation of the final <code>egrep</code> writes to the same <code>stdout</code>, so all the output goes to the same file.</p> <p>The <code>/dev/null</code> is there in case <code>xargs</code> only finds one line of input (for example, becuase you only have one file or when bundling up files, the last bundle only has one file). If you call <code>egrep</code> with a single file, it does not print the file name. Since you specifically said you want the file names, telling <code>egrep</code> to search <code>/dev/null</code> guarantees there will always be at least two files. Since <code>/dev/null</code> is guaranteed to be empty, you will never find anything in it, and it will not show up in your output.</p> <p><code>xargs</code> works great with <code>find</code>. If you wanted to search for "foo" in all the ".txt" files in the current directory and its subdirectories:</p> <pre><code>find . -name "*.txt" -print | xargs egrep foo /dev/null </code></pre> <p>would do the trick. If you have file names with spaces in them, they won't get quoted and <code>egrep</code> will get confused, so use the <code>-print0</code> option on <code>find</code> and the <code>-0</code> option on xargs:</p> <pre><code>find . -name "*.txt" -print0 | xargs -0 egrep foo /dev/null </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload