prepend

Prepend data from one file to another

雨燕双飞 提交于 2019-11-30 13:47:30
How do I prepend the data from file1.txt to file2.txt? The following command will take the two files and merge them into one cat file1.txt file2.txt > file3.txt; mv file3.txt file2.txt You can do this in a pipeline using sponge from moreutils : cat file1.txt file2.txt | sponge file2.txt Another way using GNU sed: sed -i -e '1rfile1.txt' -e '1{h;d}' -e '2{x;G}' file2.txt That is: On line 1, append the content of the file file1.txt On line 1, copy pattern space to hold space, and delete pattern space On line 2, exchange the content of the hold and pattern spaces, and append the hold space to

What is the idiomatic way to prepend to a vector in Clojure?

自闭症网瘾萝莉.ら 提交于 2019-11-30 12:55:30
问题 Prepending to a list is easy: user=> (conj '(:bar :baz) :foo) (:foo :bar :baz) Appending to a vector is easy: user=> (conj [:bar :baz] :foo) [:bar :baz :foo] How do I (idiomatically) prepend to a vector, while getting back a vector? This does not work as it returns a seq, not a vector: user=> (cons :foo [:bar :baz]) (:foo :bar :baz) This is ugly (IMVHO): user=> (apply vector (cons :foo [:bar :baz])) [:foo :bar :baz] Note: I basically just want a datastructure that I can append and prepend to.

What is the difference between 'include' and 'prepend' in Ruby?

半腔热情 提交于 2019-11-30 11:19:45
From the Module Module#append_features(mod) → mod => When this module is included in another, Ruby calls append_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to add the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors. Module#prepend_features(mod) → mod => When this module is prepended in another, Ruby calls prepend_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to overlay the constants, methods, and module

What is the idiomatic way to prepend to a vector in Clojure?

北城余情 提交于 2019-11-30 04:10:23
Prepending to a list is easy: user=> (conj '(:bar :baz) :foo) (:foo :bar :baz) Appending to a vector is easy: user=> (conj [:bar :baz] :foo) [:bar :baz :foo] How do I (idiomatically) prepend to a vector, while getting back a vector? This does not work as it returns a seq, not a vector: user=> (cons :foo [:bar :baz]) (:foo :bar :baz) This is ugly (IMVHO): user=> (apply vector (cons :foo [:bar :baz])) [:foo :bar :baz] Note: I basically just want a datastructure that I can append and prepend to. Appending to large lists should have a large performance penalty, so I thought of vectors.. Vectors

What is the difference between 'include' and 'prepend' in Ruby?

核能气质少年 提交于 2019-11-29 17:21:09
问题 From the Module Module#append_features(mod) → mod => When this module is included in another, Ruby calls append_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to add the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors. Module#prepend_features(mod) → mod => When this module is prepended in another, Ruby calls prepend_features in this module, passing it the

How to prepend to a file (add at the top)

妖精的绣舞 提交于 2019-11-29 13:15:37
Imagine you have a file sink("example.txt") data.frame(a = runif(10), b = runif(10), c = runif(10)) sink() and would want to add some header information, like /* created on 31.3.2011 */ /* author */ /* other redundant information */ How would I add this "header"? Doing it manually seems trivial. Hit a few Enters, copy/paste or write information and you're done. Of course, in R, I could read in example.txt , create example2.txt , add header information and then example.txt . I was wondering if there's another way of appending files from the "top". Other solutions (from c++ or Java...) also

What's the difference between `::` and `+:` for prepending to a list)?

大兔子大兔子 提交于 2019-11-28 22:22:25
List has 2 methods that are specified to prepend an element to an (immutable) list: +: (implementing Seq.+: ), and :: (defined only in List ) +: technically has a more general type signature— def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[List[A], B, That]): That def ::[B >: A](x: B): List[B] —but ignoring the implicit, which according to the doc message merely requires That to be List[B] , the signatures are equivalent. What is the difference between List.+: and List.:: ? If they are in fact identical, I assume +: would be preferred to avoid depending on the concrete implementation

Prepend a single line to file with Ruby

扶醉桌前 提交于 2019-11-28 21:27:18
I'd like to add a single line to the top a of file with Ruby like this: # initial file contents something else # file contents after prepending "hello" on its own line hello something else The following code just replaces the contents of the entire file: f = File.new('myfile', 'w') f.write "test string" This is a pretty common task: original_file = './original_file' new_file = original_file + '.new' Set up the test: File.open(original_file, 'w') do |fo| %w[something else].each { |w| fo.puts w } end This is the actual code: File.open(new_file, 'w') do |fo| fo.puts 'hello' File.foreach(original

Need help with: jquery prepend doctype to html

天涯浪子 提交于 2019-11-28 14:03:23
Here's my situation: I am editing an application's CSS style sheet. I can ONLY edit the CSS style sheet (unless I can creatively glom onto another file using the CSS, or possibly add a small jQuery prepend statement in an existing .js) Application is ONLY ie6, ie7 and ie8 compliant. They never use FireFox, and it's not an option. Looking for help with: 1) I think I need to use jQuery to "prepend/prependTo" a "doctype " on to html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" Without the !doctype it throws ie8 into quirksmode and of course doesn't accept any styles such as "input

Prepending Data to a File

馋奶兔 提交于 2019-11-28 13:40:57
There's no way in any operating system I'm aware of for a program to prepend data to a file efficiently. And yet, this doesn't seem difficult -- the file system can add another extent to a file descriptor if needed. So the question is, why don't operating systems implement this (rather trivial) operation? I don't think it's as easy as you suggest. It's true that the file-system could allocate a new block, store the prepended data in it, change the file pointer to point to that block and then chain the rest of the file from that block. Just like adding a node to the front of a linked list,