w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Remove duplicate lines from multiple text files
I tested this, it works. Order of lines is not maintained within each file, but you said in a comment that you're already applying sort, so that doesn't matter. It's a little roundabout, but it does work: #!/bin/bash #The number of files you have, named like file1.txt, file2.txt, etc. # If named otherwise, cahnge the definition of variable "file" in the loop below. NUM_FILES=3 #These files will be created and removed during the script, so make sure they're # not files you already have around. tempfile1="_all.txt" tempfile2="_tmp.txt" sort -u file1.txt > file1out.txt cat file1out.txt > $tempfile1 for i in $(seq 2 $NUM_FILES) do prev=$((i-1)) pofile="file${prev}out.txt" file="file$i.txt" ofile="file${i}out.txt"

Categories : PHP

Replacing multiple lines of text using sed
One way: $ sed '3,$s/S*$/*/' file Total users: * * * This does the substitution s/S*$/*/ from the third line in the file till the last line 3,$ where the substitution replaces any none whitespace characters till the end of line with a single *. Modified the substitution command as appropriate for your actual file as this will fail if you allow spaces in usernames. A more robust replacement might be: $ sed -r '3,$s/(s+).*/1*/' file Total users: * * * This will replace after the initial whitespace with a single *. Use the -i option if you want to store the changes back to the file: $ sed -ri '3,$s/(s+).*/1*/' file Edit: To replace all users with a single *: $ sed -r '3{s/(s+).*/1*/;q}' file Total users: * Although creating this file would have been

Categories : Bash

Replacing multiple occurrences of text with jQuery in IE8
If you are just trying to modify the class list would it be possible just to directly set the class names from inside your each loop? $("td.t-header").each(function() { this.className = "t-header rr-header rr-header-text"; }); Another solution using Jqueries toggle class is listed here: http://stackoverflow.com/a/2576780/2511885

Categories : Jquery

Unix Script - finding duplicate strings in a multiple dat files
Save following code as dups.py, and run python dups.py < merged_file.dat (This is not shell script. You need python to run.) #!/usr/bin/env python import sys import collections d = collections.defaultdict(list) for lineno, line in enumerate(sys.stdin, start=0): row = line.strip().split('|') if len(row) == 4: key = '{0[0]}|{0[2]}|{0[3]}'.format(row) d[key].append(lineno) for line in d: linenos = d[line] if len(linenos) > 1: print('{};{} Occurances;line no {}'.format( line, len(linenos), ' & '.join(map(str, linenos))) ) Sample output: $ cat test.dat ID|source_code|Full_Name|AGE 123|01|John|20 190|05|Mary|35 123|05|John|20 180|09|John|30 190|100|Seam|20 190|900|Jack|10 $ python dups.py < test.dat 123|John|20;lin

Categories : Shell

Remove duplicate text from multiple strings
def common_prefix_length(*args) first = args.shift (0..first.size).find_index { |i| args.any? { |a| a[i] != first[i] } } end def magic(*args) i = common_prefix_length(*args) args = args.map { |a| a[i..-1].reverse } i = common_prefix_length(*args) args.map { |a| a[i..-1].reverse } end a = "This is Product A with property B and propery C. Buy it now!" b = "This is Product B with property X and propery Y. Buy it now!" c = "This is Product C having no properties. Buy it now!" magic(a,b,c) # => ["A with property B and propery C", # "B with property X and propery Y", # "C having no properties"]

Categories : Ruby

Gradle Error - Duplicate Files copied in APK AndroidManifest.xml
I don't think that you can reference the Evernote Android SDK through maven with Android Studio. The problem stems from the fact that Android libraries can't be packaged as a simple jar. The Evernote library was built using the maven-android-plugin which isn't compatible with the Android Studio gradle plugin. This is because the maven plugin uses the apklib format for redistributing libraries, whereas gradle uses the new aar format. That's why gradle is having trouble merging Evernote's AndroidManifest with your own, resulting in duplicates. Instead, you'll have to clone the Evernote SDK's source, manually import it into Android Studio, and refer to it that way. Their readme includes instructions for doing this with Intellij, which should be the same as Android Studio.

Categories : Android

combine multiple text files into one text file using python
You could try something like this: import glob files = glob.glob( '*.txt' ) with open( 'result.txt', 'w' ) as result: for file_ in files: for line in open( file_, 'r' ): result.write( line ) Should be straight forward to read.

Categories : Python

Error in creating .so file from .o files generated using multiple .c files
The problem is that you're linking the object files, not just compiling them. Make sure that you only compile the files, don't link them! You do that using the -c option. Do not use the -l option, you don't want to link anything at this stage. So: gcc -c -o usb_comm.o usb_comm.c gcc -c -o hex2bin.o hex2bin.c gcc -c -o hex_read.o hex_read.c gcc -c -o crc32.o crc32.c (I omitted the -I flags to save space here.) Then finally link all those object files into a shared library, and link against usb-1.0: gcc -shared -o libhello.so usb_comm.o hex2bin.o hex_read.o crc32.o -lusb-1.0 You should use a Makefile though for this. Or, even better, use a proper build system, like CMake, which is very easy to use. It's provided by all common Linux distros, so simply install it with the package man

Categories : C

XCode: 'Warning: Multiple build commands for output file' but I get error if I delete the duplicate
If you set the splash/launch icon from xcode (tagets -> summary..) the xcode has an annoying feature that will copy your png file into the root folder, and after that you will get the warning for "Multiple build commands". What you need to do is, delete your png file used for splash/launch and also check the copy bundle resources in target section and make sure your file has been removed from there. It will appear in red if the file is removed from your project and not removed from copy bundle resources.

Categories : IOS

Fastest way to search text in multiple files?
Here what I will if I where you: 1- I'll load all files path to a list of string. 2- I'll create a new list to store files path that match my search term. 3- I'll loop foreach in Files list and search for my term then I'll add the matched file to the new list. string searchTerm = "Some terms"; string[] MyFilesList = Directory.GetFiles(@"c: xtDirPath", "*.txt"); List<string> FoundedSearch=new List<string>(); foreach (string filename in MyFilesList) { string textFile = File.ReadAllText(filename); if (textFile.Contains(searchTerm)) { FoundedSearch.Add(filename); } } then you can deal with the List:FoundedSearch what ever you want. by the way: I don't know the best answer but the performance will be very well

Categories : C#

Using command prompt batch files to move and automatically rename duplicate files
I have a pair of utility files that do this, so I can call from either command line, or another batch file. This manages several versions of the file in the same folder, and I would call it before moving your new file in. Usage is: archivefile 5 "c: empsongs" .txt [move] Where 5 is the number of versions to keep. The base file name in this example is "c: empsongs.txt" and it creates (in c: emp) 5 files: songs_1.txt songs_2.txt songs_3.txt songs_4.txt songs_5.txt If you specify move it will move the original songs.txt otherwise it copies it. Note, if you're using it from another batch file (which you'll probably want to), you need to use call or it won't return to your original batch file (both batch files will exit instead, which isn't what you want): call archivefile 5 "c: empsong

Categories : Windows

According to files names of a file, duplicate files into anther directory
You need to turn the first file into a set (for fast membership testing). You are also using os.walk, which gives you three pieces of information, the path to the directory, a list of subdirectories and a list of the files in that directory: import sys import shutil,errno import os srcDir = 'Root' dstDir = 'De' with open('file.txt','r') as f: read_filenames = {fname.strip() for fname in f} # set comprehension for root, directories, files in os.walk(srcDir): for filename in read_filenames.intersection(files): shutil.move(os.path.join(root, filename), dstDir) The .intersection() call returns all elements in the read_filenames set that are also in the files list. Note that I tell shutil.move() the full path of the file to move to dstDir, using os.path.join() based on th

Categories : Python

How can I use the command line to combine multiple text files?
There are different ways: I tested with f1, f2, f3. If the name follows the pattern fXX, it can be done like this: $ paste f* abc123 2468, def zyx987 $ paste -d' ' f* #set space as delimiter abc123  2468, def zyx987 $ cat f* abc123 2468, def zyx987 If you want the output to be a file, just add > result $ cat f* > result $ cat result abc123 2468, def zyx987

Categories : Unix

Multiple Text Files to a Single Output (Matlab)
You could do this outside of MATLAB: click here if you're on OSX/Linux click here if you're on Windows If you really want to stick to MATLAB, A = []; for ii = 1:length(files) % load new contents newA = load(files(ii).name, '-ascii'); % concatenate horizontally A = [A newA]; %#ok end % save final output save('outputFile.txt', 'A')

Categories : Matlab

Importing and parsing multiple text files into single XLS?
Restating the task/problem: Given a lot of structured text files in a folder, extract from each file three (or a multiple of three?) data items (ILPN Number, MAC Address, Test Result) and put them as rows in a .txt/.csv file that can be red by/imported into Excel. Idea: Loop over the files, read each into memory, parse/extract the data triple(s) using a RegExp, write them into the output file; use Excel to open the output file, do further manipulation manually. Plan: Use a VBScript from the command line to keep things simple. [If that look good to you and you can answer the question "Does each input file contain one or more info triple(s)?", I'm willing to add some proof of concept code to this concept.] While you wait: Given your additional info, I believe that @Ansgar's assumptio

Categories : Excel

Calling random line from multiple text files
You can put your logic into a function that takes the file name as parameter, and at the same time put the random pick into that function: import random def pick_random(filename): contents=[] with open(filename) as a: for line in a: line=line.strip() contents.append(line) return contents[random.randint(0,len(contents)-1)] print "Welcome!" print "" print "a:", pick_random("a.txt") print "b:", pick_random("b.txt") You can call the function for each file you want to pick a line from, either by calling them one by one like above, or putting all files into a list and looping over them. This is a straightforward extension to your code, but consider falsetru's answer for a clearer solution. Using random.choice makes it more explicit what you want

Categories : Python

read multiple text files and count the occurances of a word?
The simplest way would be to create a map of strings to ints. std::map<std::string, int> And then increment the containing int, or add to the map if it doesn't exist. http://www.cplusplus.com/reference/map/map/ If you're using c++11(I think) or later, you can even use unordered_map, which instead of using sorting to access elements uses hashing. This is an optimization you could look into, if performance matters. Here's some sample code to get you started #include <iostream> #include <map> #include <string> using namespace std; void incrementString(map<string, int> &theMap, string &theString) { if(theMap.count(theString)) { theMap[theString]++; } else { theMap[theString] = 1;//This fixes the issue the other poster menti

Categories : C++

how to find frequency of the keys in a dictionary across multiple text files?
Well, I'm not exactly sure what you mean by all the files in the document "X" but I assume it's analogous to pages in a book. With this interpretation, I would do my best to store the the data in the easiest way. Putting data in easily manipulable adds efficiency later, because you can always just add a method for accomplishing and type of output you want. Since it seems the main key you're looking at is keyword, I would create a nested python dictionary with this structure dict = (keyword:{file:count}) Once it's in this form, you can do any type of manipulation on the data really easily. To create this dict, import os # returns the next word in the file def words_generator(fileobj): for line in fileobj: for word in line.split(): yield word word_count_dict

Categories : Python

ADO.NET - Error reading multiple xml files
It looks like your DataSet can read only one xml file at a time. ds.ReadXml(ms); Try if you can get all 3 xml files through XmlReader. That will tell you something.

Categories : C#

Error when trying to open multiple files in c ++
You already opened your files once. You don't need to open them again. The std::ifstream constructor is opening each file, then your invoking .open() for no reason. Remove the inputFile.open() line. Change this: ifstream inputFile(filename.c_str(), ios::in); inputFile.open(filename.c_str()); To this: ifstream inputFile(filename.c_str());

Categories : C++

Error when Saving and writing text files while program is in jar
That’s the strangest thing I’ve seen for long: FileWriter fstream = new FileWriter(new File(".").getAbsolutePath()+File.separator+playerName + ".txt",true); getLogger().log(Level.INFO,"trying to save text document to " + new File("").getAbsolutePath()+File.separator+playerName + ".tct"); Try to clean up: File f=new File(playerName + ".txt"); FileWriter fstream = new FileWriter(f, true); getLogger().log(Level.INFO,"trying to save text document to " + f.getAbsolutePath()); Next thing: you should always close files after working with then. Then your file names do not match. One time it is playername+".txt" the next time it is just playername But the biggest mistake: Integer i = Integer.getInteger(reader.readLine()); return i.intValue(); Integer.getInteger does not parse the str

Categories : Java

read multiple xml files from the folder and write one output text file(comma separated)
Use this to iterate all files in your directory: Read all files in a folder Output (file in dir) use as input here Document doc = builder.parse("<dir file>"); If file is not xml, it either return null or exceprion is raised (I dont know currently). Eitherway, you will have to solve this.

Categories : Java

Multple c++ files causes "multiple definition" error?
If the Line you quoted after "CODE" is in a header file you can either: add inline to the definition or remove the function body from the header and put it into 1 (and only 1) of your source files.

Categories : C++

Replacing Jar files within Tomcat in Eclipse
If you see a jar file in Apache Tomcat libraries, it means you have it under the ${tomcat_home}/lib folder. If you want to remove it from global .classpath you should remove it from lib folder manually and then refresh your project in eclipse.

Categories : Eclipse

Working with files - replacing one line
Look at available constructors for std::istream_iterator: istream_iterator(); constexpr istream_iterator(); istream_iterator( istream_type& stream ); istream_iterator( const istream_iterator& other ) = default; You're trying to call third constructor, but you pass a rvalue, while a lvalie is expected.

Categories : C++

Error upon sending and executing multiple test files
Here is your code re-factored. The sleeps/gotos were really bothering me. I couldn't really test it, but I think it should work the same. Let me know if it doesn't work or you have any questions. This assumes your listbox has content like this in it: testname.cmd test2.cmd test3.exe lasttest.bat Here is my attempt: public void executeCommandFiles() { foreach (string test in listboxTestsToRun.Items) { //gets the directory name from given filename (filename without extension) //assumes that only the last '.' is for the extension. test.1.cmd => test.1 string testName = test.Substring(0, test.LastIndexOf('.')); //set up a FileInfo object so we can make sure the test exists gracefully. FileInfo testFile = new FileInfo(@"Y:Tests" + testN

Categories : C#

Swiffy replacing v5.2 to v5.1 making the files not working
Yeah, relying on a online "compiler" makes large product development and maintenance darn near impossible or at least terribly frustrating. I've asked Google numerous times for a stand alone compiler, and they aren't interested in sharing it right now. We've just got to move along with them and rebuild every file with each update for reasons similar to yours. Here is a possible work-around for you: <style type="text/css" media="screen"> #div > *:first-child { background-color: transparent !important; } </style>

Categories : Misc

Duplicate span text into a text field in a form
You could always do the following function calculateSum() { var sum=0; $(":text").each(function() { if(!isNaN(this.value) && this.value.length!=0 { sum+=parseFloat(this.value); } }); $("#sum").html(sum.toFixed(0)); $("#myTextField").val(sum.toFixed(0)); //adding to text field }

Categories : Javascript

Replacing text in tag which contains an
Well, that's because you replace the whole content of the a tag. Try somehting like this: $(function(){ var selectCount = 0; $("#bin").click(function(){ selectCount++; $(this).html('<i class="icon-trash"></i> Remove Selected ('+selectCount+')'); }); }); Fiddle: http://jsfiddle.net/FZWyj/18/

Categories : Javascript

When using resx files, can you have variables replacing with constant values
You can achieve this by creating your own resource manager. Perhaps its more effort than you want to undertake, but it is guaranteed to meet your needs. http://msdn.microsoft.com/en-us/library/aa905797.aspx

Categories : C#

Replacing text in a .txt file (C++)
You are opening the same file for reading and writing and then not checking the status. This is likely to cause problems (depending on your OS). As a quick test, change your output_file to write to a different file name and see if you get the expected results.

Categories : C++

Python script write multiple CSV files into SQL Server table error
You can skip the first line this way: csv_data.next() #throw away first row for row in csv_data: if len(row) >= 10: cursor.execute("INSERT ..." ...) Also, you should check to make sure that row contains enough elements before executing: if len(row) >= 10: #use first ten values in row, if there are at least ten cursor.execute("INSERT ...", row[:10]) You currently have your insert statement listed as two strings next to each other. This has the effect of joining them together with no space in between. You may want a space before "VALUES".

Categories : Python

How to duplicate Console text to text file?
Create a class derived from TextWriter Allow it to takes as many instances of you want (say writers) Implement TextWriter in your derived class to output the data to every instance of writers Create an instance of your derived class (eg: new Foo(Console.Out, File.CreateText("Foo"))) Console.SetOut(the_instance_of_your_textwriter) PROFIT!!!

Categories : C#

Android Studio build error - Multiple dex files define Landroid/support/v4/
For anyone who is interested, I solved my own problem. My mistake was that I had pasted android-support-v4.jar and google-play-services.jar in all of my project's module lib folders (my project consists of 3 modules). What I had to do instead was to paste these jars only into my main module's lib folder, and the other modules would automatically reference them.

Categories : Android

QT: Finding and replacing text in a file
If the required change, for example is to replace the 'ou' with the american 'o' such that "colour behaviour flavour neighbour" becomes "color behavior flavor neighbor", you could do something like this: - QByteArray fileData; QFile file(fileName); file.open(stderr, QIODevice::ReadWrite); // open for read and write fileData = file.readAll(); // read all the data into the byte array QString text(fileData); // add to text string for easy string replace text.replace(QString("ou"), QString("o")); // replace text in string file.seek(0); // go to the beginning of the file file.write(text.toUtf8()); // write the new text back to the file file.close(); // close the file handle. I haven't compiled this, so there may be errors in the code, but it gives you the outline and general idea of what

Categories : C++

Find and replacing text in elementtree
Replace text, tail attributes. import lxml.etree as ET with open('1.xml', 'rb+') as f: tree = ET.parse(f) root = tree.getroot() for elem in root.getiterator(): if elem.text: elem.text = elem.text.replace('VirtualBox', 'Xen') if elem.tail: elem.tail = elem.tail.replace('VirtualBox', 'Xen') f.seek(0) f.write(ET.tostring(tree, encoding='UTF-8', xml_declaration=True)) f.truncate()

Categories : Python

Replacing span text within href tag
You probably are not adding the class to the <a> element correctly. Your jQuery code is looking for this $("a.productdesc"), I suggest changing the first line of code to inside the $(function() {. Btw your code is missing a .find(), you can use like this: $(function() { $('a[href^="#pdpTab1"]').addClass('productdesc'); // you should add this class to the html instead. $("a.productdesc").each(function(index,el){ $(el).find('span').text('Descripción del producto'); }); });

Categories : Javascript

Using css for replacing text on click (instead of jquery)?
jsfiddle Use this as html: <input type="checkbox" id="toggle"> <label id="shown" for="toggle"> What is stackoverflow? </label> <label id="hidden" for="toggle" > A language-independent collaboratively edited question and answer site for programmers. </label> And this for css: input[type=checkbox] { position: absolute; top: -9999px; left: -9999px; } #shown { display: block; } #hidden { display: none; } #toggle:checked ~ #hidden{ display: block; } #toggle:checked ~ #shown { display: none; }

Categories : Jquery

Apache POI Word .DOC Replacing Text
This presents the alternatives. It is in the context of docx4j, but the options also apply in principle to POI.

Categories : Apache

Replacing a text node by another in xml using python
I noticed you're using Python 3 (input()) instead of Python 2 (raw_input()). Why exactly are you trying to use regular expressions (the re module)? As I understand what you're trying to do, you're trying to parse an XML file into a DOM, find a <p> element identified by its name attribute, replace its text with user-supplied text, and write it out to a new file. You can do the replacing far more reliably by manipulating the DOM than by trying to run regular expressions on the raw XML stream. The following Python 3 program shows how to manipulate the DOM: #!/usr/bin/env python3 from xml.dom import minidom import os.path def new_value(parameter, parameter_value, target_dir, inputfile): # Load the XML file and parse it dom = minidom.parse(inputfile) # Find all <p> e

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.