Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>header="/name/of/file/containing/header" for file in "$@" do cat "$header" "$file" &gt; /tmp/xx.$$ mv /tmp/xx.$$ "$file" done </code></pre> <p>You might prefer to locate the temporary file on the same file system as the file you are editing, but anything that requires inserting data at the front of the file is going to end up working very close to this. If you are going to be doing this all day, every day, you might assemble something a little slicker, but the chances are the savings will be minuscule (fractions of a second per file).</p> <p>If you really, really must use <code>sed</code>, then I suppose you could use:</p> <pre><code>header="/name/of/file/containing/header" for file in "$@" do sed -e "0r $header" "$file" &gt; /tmp/xx.$$ mv /tmp/xx.$$ "$file" done </code></pre> <p>The command reads the content of header 'after' line 0 (before line 1), and then everything else is passed through unchanged. This isn't as swift as <code>cat</code> though.</p> <p>An analogous construct using <code>awk</code> is:</p> <pre><code>header="/name/of/file/containing/header" for file in "$@" do awk '{print}' "$header" "$file" &gt; /tmp/xx.$$ mv /tmp/xx.$$ "$file" done </code></pre> <p>This simply prints each input line on the output; again, not as swift as <code>cat</code>.</p> <p>One more advantage of <code>cat</code> over <code>sed</code> or <code>awk</code>; <code>cat</code> will work even if the big files are mainly binary data (it is oblivious to the content of the files). Both <code>sed</code> and <code>awk</code> are designed to handle data split into lines; while modern versions will probably handle even binary data fairly well, it is not what they are designed for. </p>
    singulars
    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.
    3. 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