append

Append text to the last line of a file in unix

≯℡__Kan透↙ 提交于 2019-12-12 18:40:17
问题 I want to append a colon character (:) at the end of the last line of a text file (not in a new line). My file already has a \n character at the end so printf ":" >> file puts the colon in a new line. Using sed '$s/$/:/' file > newfile works, but my file is ~100 MB so piping the whole thing just to add a single character seems unattractive. Is there a better solution? 回答1: You could go with dd and notrunc (tested on Linux 4.12): printf ":" | dd of=file conv=notrunc bs=1 seek=$(( $(stat -c "%s

append the same element to several sublists in python

折月煮酒 提交于 2019-12-12 17:56:15
问题 I have a list of lists like this: L=[[[1,2,3],[4,5]],[[6,7,8,9],[10]]] I want to append the integer 11 to the subsublists 1 and 3. I can do something like: L[0][2].append(11) L[1][2].append(11) Is there a simpler way to do it in Python ? Because in my case, let's say I have a list with 100 sublists, and these sublists have 100 sublists (comparable to a (100,100)-matrix) and I want to append a value to the sublists from nb 50 to 75 of the sublists from nb 10 to 20. So right now I do something

Save html in cookie

为君一笑 提交于 2019-12-12 17:05:22
问题 I am using jquery to clone and append some html into a div. My problem is that this html will be removed when the page is refreshed. The question is how I can save the appended HTML in the div (the html code will contain some inputs and select lists and there will be plenty of code). What should I look into? Cookies? HTML5? Anything else? 回答1: If you're only going to support modern browsers I would go for HTML5's offline storage. Another approach would be to get the AJAX route. You don't want

jQuery each returns [object Object]

久未见 提交于 2019-12-12 16:29:03
问题 My problem is that the html variable returns something like this: [object Object][object Object][object Object][object Object][object Object], instead of the elements. What should i do different? var html = ''; $.each(data.response, function(index, value) { var tr = $('<tr>'); var tr_data = '<td>asd</td>'; html += tr.data('trackinfo',value).html(tr_data); }); $(target).html(html); 回答1: That's because you're setting the data on the tr and then filling it with your html, but still concatinating

Python Strange Behavior with List & Append

喜夏-厌秋 提交于 2019-12-12 16:01:53
问题 The following code is an issue I encountered and am looking for an explanation. The behavior of the code different than what I expected. Below the code will be my expected output, and the actual output. One last thing to note, is that I understand this code may be 'strange', and that using range(1) is a bit odd to say the least. The reason for this is that this exact occurrence in a program (the ranges were variables but at these values) caused problems.. so I made this simple code to

jQuery - add element after text

蓝咒 提交于 2019-12-12 14:50:57
问题 i have a navigation with some links: <ul class="nav"> <li> <a class="active">linkname</a> <li> </ul> now i need to add extra content directly after "linkname" like this: <ul class="nav"> <li> <a class="active">linkname<b class="caret"></b></a> <li> </ul> how can i add elements (div,span,b) directly after specific text? 回答1: Try .append() $('ul.nav a.active').append('<b class="caret"></b>'); fiddle Demo 回答2: $("a.active").append("<b class='caret'></b>"); 回答3: $('a.active').html($('a.active')

Crashed HDFS client - how to close remaining open files?

我的未来我决定 提交于 2019-12-12 12:26:36
问题 I am experiencing some problems with my Hadoop application. Whenever my client exits without closing the files (e.g. due to a crash), there are open files in Hadoop that are never closed. When I then try to restart the client it fails when re-opening those files to append data. (See below for Exception message) Is there a good way to close those files manually or even better, a way to check and close them directly before reopening them? I am using Cloudera CDH5 (2.3.0-cdh5.0.0). These are my

Is there a reason why append and insert are both there?

此生再无相见时 提交于 2019-12-12 10:44:45
问题 I'm surely not the Python guru I'd like to be and I mostly learn studying/experimenting in my spare time, it is very likely I'm going to make a trivial question for experienced users... yet, I really want to understand and this is a place that helps me a lot. Now, after the due premise, Python documentation says: 4.6.3. Mutable Sequence Types s.append(x) appends x to the end of the sequence (same as s[len(s):len(s)] = [x]) [...] s.insert(i, x) inserts x into s at the index given by i (same as

Implementing basic library functions in LISP (manually)

醉酒当歌 提交于 2019-12-12 10:07:55
问题 Is there any way by which I can define functions my_list , my_cons , my_append which perform similar function as list , cons and append respectively? Otherwise where can I find the implementation of these functions? Thanks 回答1: For my_list and my_append, the solutions are: (defun my_list (&rest arguments) `(,@arguments) ) (defun my_append (a_list an_item) `(,@a_list ,an_item) ) (my_append (my_list 'a 'b 'c) 'd) I'm probably wrong but I dont know any alternative method to make pairs, so an

jsPDF - include other pdf

£可爱£侵袭症+ 提交于 2019-12-12 10:07:04
问题 I'm trying to solve such problem with jsPDF: I have PDF file, which is stored on server. I'm generating another pdf with jsPDF and trying to append to already existed pdf file (as I mentioned above) as a another page. I googled about it, but can't find any help. Also I found this question on stackoverflow, but it is different scenario - Append Existing Pdf to Jspdf How can I make this to work? Or is any other plugin or something else to make this? 回答1: Unforfortunately, with jsPDF today (2018