text-files

How to cat two files after each other but omit the last/first line respectively?

三世轮回 提交于 2019-11-30 18:07:35
I have two files I want to cat together. However, the last line of the first file and the first line of the last file should be omitted. I am sure this can be done in a UNIX shell (or rather, Cygwin). But how? $ head --lines=-1 file1 > res $ tail --lines=+2 file2 >> res you can use: head -n -1 file1 && tail -n +2 file2 head shows the first lines of a file, the param -n shows the first n lines of the file, but if you put a - before the number, it shows all the file except the last n lines. tail is analog.. for better reference: man head man tail head -n -1 file1 will print all lines in file1

Searching for string within a text file in R [closed]

孤街醉人 提交于 2019-11-30 17:43:38
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Is there an R function that would search for s string within a text file? Something like unix grep? I guess the alternative will be to read the file line by line but was wondering if that can be bypassed by such a function? 回答1: 1) Read it in and use R's grep : # test input cat("a 1\n\b 2\nc 3\n", file = "myfile

When downloading a file from ASP .Net, the text file gets appended with HTML content

血红的双手。 提交于 2019-11-30 17:20:36
问题 I have made a page that allows users to upload files to the server using a FileUpload Control and handling its event with this code Sub SaveAttachment() Dim root As String = "C:\temp\" Dim filename As String = FileUpload1.FileName Dim SaveName As String = root & filename FileUpload1.SaveAs(SaveName) End Sub That worked fine, I was able to see files getting uploaded, and the content of the files is intact (exactly a duplicate copy of the file that the user's upload). Now for downloading the

Easiest way to read text file which is locked by another application

≯℡__Kan透↙ 提交于 2019-11-30 17:11:23
I've been using File.ReadAllText to grab some csv, but every time I forget to close the file in Excel, the application throws an exception because it can't get access to the file. (Seems crazy to me, I mean the READ in ReadAllText seems pretty clear) I know that there is File.Open with all the bells and whistles, but is there an 'intermediate' method which doesn't involve messing around with buffers and char arrays? Yes, I'm lazy, so vote me down, just give me the answer first :) Noldorin I think you just want the following: using (var fileStream = new FileStream("foo.bar", FileMode.Open,

Windows XP batch file concat

旧城冷巷雨未停 提交于 2019-11-30 16:57:51
I'm trying to accomplish the following ridiculous task: I have a text file containing a set of fully qualified filesnames. I want to iterate through the file and append each line to a common variable, that can be passed to a command line tool. For example, the file might be: C:\dir\test.txt C:\WINDOWS\test2.txt C:\text3.txt and I'd like to assign them to some variable 'a' such that: a = "C:\dir\test.txt C:\WINDOWS\test2.txt C:\text2.txt" A secondary question is - what is a good batch file reference? I'm finding some stuff in the Windows material, and a lot of home-grown websites, but nothing

text file: Reading line by line C#

江枫思渺然 提交于 2019-11-30 16:53:53
问题 So, let's say i have a text file with 20 lines, with on each line different text. i want to be able to have a string that has the first line in it, but when i do NextLine(); i want it to be the next line. I tried this but it doesn't seem to work: string CurrentLine; int LastLineNumber; Void NextLine() { System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt"); CurrentLine = file.ReadLine(LastLineNumber + 1); LastLineNumber++; } How would i be able to do this? Thanks in advance

how to parse unicode that is read from a file in java [duplicate]

假装没事ソ 提交于 2019-11-30 16:12:06
This question already has an answer here: How to unescape a Java string literal in Java? 10 answers I have written a text file with the following contents: \u0032\u0142o\u017Cy\u0142 Then I have used FileReader und BufferedReader to read the file. public static void main(String[] args) throws Exception{ FileInputStream fr = new FileInputStream("README.TXT"); BufferedReader br = new BufferedReader(new InputStreamReader(fr,"UTF-8")); String s=""; while((s=br.readLine())!=null){ System.out.println(s); } } But the output is: \u0032\u0142o\u017Cy\u0142 . When I used System.out.println("\u0032

Python: load words from file into a set

…衆ロ難τιáo~ 提交于 2019-11-30 14:30:58
问题 I have a simple text file with several thousands of words, each in its own line, e.g. aardvark hello piper I use the following code to load the words into a set (I need the list of words to test membership, so set is the data structure I chose): my_set = set(open('filename.txt')) The above code produces a set with the following entries (each word is followed by a space and new-line character: ("aardvark \n", "hello \n", "piper \n") What's the simplest way to load the file into a set but get

Searching for a Specific Word in a Text File and Displaying the line its on

只谈情不闲聊 提交于 2019-11-30 14:03:43
I am having trouble attempting to find words in a text file in C#. I want to find the word that is input into the console then display the entire line that the word was found on in the console. In my text file I have: Stephen Haren,December,9,4055551235 Laura Clausing,January,23,4054447788 William Connor,December,13,123456789 Kara Marie,October,23,1593574862 Audrey Carrit,January,16,1684527548 Sebastian Baker,October,23,9184569876 So if I input "December" I want it to display "Stephen Haren,December,9,4055551235" and "William Connor,December,13,123456789" . I thought about using substrings but

Using Hibernate to work with Text Files

假如想象 提交于 2019-11-30 13:29:10
I am using Hibernate in a Java application to access my Database and it works pretty well with MS-SQL and MySQL. But some of the data I have to show on some forms has to come from Text files, and by Text files I mean Human-Readable files, they can be CSV, Tab-Delimited, or even a key, value pair, per line since my data is as simple as this, but my preference of course is XML files. My question is: Can I use hibernate to read those files using HQL, Query , EntityManager and all those resources Hibernate provides me to access files. Which file format should I use and How I configure My