Search Results

Search found 33940 results on 1358 pages for 'line numbers'.

Page 16/1358 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • php - efficent way to get and remove first line in file

    - by Marco Demaio
    Hello, I have a script that each time is called gets the 1st line of a file. Each line is known to be exactly of the same length (32 alphanumerci chars) and terminates with a "\r\n". After getting the 1st line, the script removes it. Now I do in this way: $contents = file_get_contents($file)); $first_line = substr($contents, 0, 32); file_put_contents($file, substr($contents, 32 + 2)); //+2 because we remove also the \r\n Obvioulsy it works, but I was wondering if there could be a smarter (or more efficent) way to do this??? In my simple solution I basically read and rewrite all the file just to take and remove the 1st line. Thanks!

    Read the article

  • batch: replace a line in a text file

    - by sasamimasas
    I'm trying to replace this line: # forward-socks5 / 127.0.0.1:9050 . with this one: forward-socks5 / 127.0.0.1:9050 . this line belongs to a config file that has to be enabled (UN-commented) by deleting the # sign from the beginning and I could not thought of a better way other than replacing the line with another without the # sign. any other thoughts or ways would be very useful. btw, the spaces before the text are there also.I have pasted the text as it was in the original file. thanks in advance EDIT: I have somehow managed to do the line addition and removing using two peaces of code that I've found. my only problem is that the following code removes every bit of exclamation in the output file! @echo off :Variables SETLOCAL ENABLEDELAYEDEXPANSION set InputFile=config.txt set OutputFile=config-new.txt set _strFind=# forward-socks5 / 127.0.0.1:9050 . set _strInsert= forward-socks5 / 127.0.0.1:9050 . set i=0 :Replace for /f "usebackq tokens=1 delims=[]" %%A in (`find /n "%_strFind%" "%InputFile%"`) do (set _strNum=%%A) for /f "usebackq delims=" %%A in ("%InputFile%") do ( set /a i = !i! + 1 echo %%A>>"%OutputFile%" if [!i!] == [%_strNum%] (echo %_strInsert%>>"%OutputFile%") ) type %OutputFile% | findstr /i /v /c:"%_strFind%">config-new2.txt I was wondering if there is any way to do both the find/delete/add line in one step (not two steps as mine)...

    Read the article

  • What steps shall I take before building a command line application using C#

    - by Mendy
    I want to develop a command line tool. I didn't build one before, but I used a few, (like mercurial). What steps do I need to take to know how to do that? So what is the problem: Regular console application need to be invoked from the command line only from it's directory. Like: C:\Projects\CommanLineProject\MyProjectConsole.exe. I want to use it from the command line from any directory, like mercurial.

    Read the article

  • How to disable Alert volume from the command line?

    - by Bryce
    There is an option in the Sound Preferences dialog, Sound Effects tab, to toggle Alert volume 'mute'. It works and suffices for my needs to disable the irritating system beep/bell. However, I reinstall systems a LOT for testing purposes and would like to set this setting in a shell script so it's off without having to fiddle with a GUI. But for the life of me I can't seem to find where this can be toggled via a command line tool. I've scanned through gconf-editor, pulseaudio's pacmd, grepped through /etc, even dug through the gnome-volume-control source code, but I am not seeing how this can be set. I gather that gnome-volume-control has changed since a few releases ago. Ideas?

    Read the article

  • How to disable Alert volume from the command line in Natty?

    - by Bryce
    There is an option in the Sound Preferences dialog, Sound Effects tab, to toggle Alert volume 'mute'. It works and suffices for my needs to disable the irritating system beep/bell. However, I reinstall systems a LOT for testing purposes and would like to set this setting in a shell script so it's off without having to fiddle with a GUI. But for the life of me I can't seem to find where this can be toggled via a command line tool. I've scanned through gconf-editor, pulseaudio's pacmd, grepped through /etc, even dug through the gnome-volume-control source code, but I am not seeing how this can be set. I gather that gnome-volume-control has changed since a few releases ago. I'm using Natty fwiw. Ideas?

    Read the article

  • How to install Chrome browser properly via command line?

    - by Bad Learner
    Setting up and managing an Ubuntu server all by myself, in coming months, is a part of my current plans. Hence, I am planning a swtich from Windows to Linux - - Ubuntu. I now need to get some grip on the command line, since I am all used to Windows' GUI. Anyway... the most obvious start is installing apps on my computer, and I thought I should learn to do it via CLI. And this is what I did: $ apt-cache search chrome browser the results showed that the proper term is "chrome-browser," so... $ sudo apt-get install chrome-browser And then "Y" for the Y/n question. But the installation threw errors. (I do not have my PC at hand, so can't mention what error exactly.) Does someone see anything wrong with the commands I issued? I am probably missing some command(s) in between, I think.

    Read the article

  • How Can I Upgrade to 11.10 from the Command Line?

    - by nmagerko
    I am trying to upgrade my 11.04 Ubuntu operating system to 11.10, as the current system is not the most recent. However, I cannot use the GUI to upgrade - as from past experience I have learned this - because my graphics hardware only works on 10.04 to 11.04 (non-inclusive) and from 11.10+. So once I can get to 11.10, I should be just fine. Because of this, I need to find a way to upgrade the OS from the command line. Can this be done? Thanks for any and all help.

    Read the article

  • How do I combine all lines in a text file into a single line?

    - by John
    I want to get all lines in a text into one line. I'm a beginner at coding trying to learn by doing. I've spent four hours trying to solve this problem. I know there's a simple solution to this problem. Here's what I've been trying. sed -e 'N;s/\n//' myfile.txt #Does nothing sed -e :a -e N -e 's/\n/ /' -e ta myfile.txt #output all messed up and I can't make head nor tail of the syntax cat myfile.txt | tr -d '\n' myfile.txt # Deletes all lines Here's the text file: 500212 262578-4-4 23200 GRIFFITH LABORATORIES LTD GRIFFITH LABORATORIES SOUTH DUBLIN COUNTY COUNCIL OFFICE OFFICE (INDUSTRIAL) List Rateable 2 Pineview Industrial Estate Firhouse Road Knocklyon 31 Dec 2007 01 Jan 2008" I can't figure out where I've gone wrong....

    Read the article

  • How do I set command line mode vga=788 permanently?

    - by George
    I have a problem that is not of easy resolution, happen to tell... I have Installed Ubuntu 10.10 Server. I want to join to the system way vga=788, into the grub it changes without any problem editing the file grub.cfg, the problem is that editing the above mentioned file I join to the system way vga=788 (800x600) and then command line puts itself in way vga=792 (1280x1024). Is there any way of changing this configuration so that it is always vga=788? tanks. sorry for my english :D

    Read the article

  • How do you change brightness, color and sharpness from command line?

    - by YumYumYum
    I am controlling my PC with SSH and scripting. How can i change the brightness, color and sharpness from command line? Try 1: failed $ sudo redshift -t 5000:5000 -g .5 Cannot list GNOME panel applets. Initialization of gnome-clock failed. Trying next provider... Latitude and longitude must be set. Try 2: failed $ cat brightness 20 $ cat max_brightness 20 $ echo 1 | sudo tee /sys/class/backlight/acpi_video0/brightness 1 $ echo 20 | sudo tee /sys/class/backlight/acpi_video0/brightness Any alternative way to do? Follow up: http://jonls.dk/redshift/ [command] [1000K to 10000K] [effects 0.1 to 10.0] | | / / / ^ ^ ^ ^ ^ redshift -t 1000:1000 -l 0:0 -g .1; Dark redshift -t 1000:1000 -l 0.0 -g 5; Bright

    Read the article

  • How do I install Ubuntu 12.04 PPC on a PowerPC G4 from commands line or fix the graphical mode?

    - by Gerardo Rodríguez
    Good afternoon. I'm new to this Linux world so I hope someone can help me . I recently got a Mac as a gift, a PowerPC G4 , which has 1GB of RAM but came with no optical drive or hard drive. So I put a dvd burner and a hard drive of 40 GB I got. Then download an iso of Ubuntu 12.04 for PowerPC and burned onto a CD. I'm trying to install from Open Firmware ( as I haven't a Mac keyboard, I use one standard ) . Finally, the Installation CD boots , but on live mode and after the Ubuntu 12.04 screen I get a message that there is a problem with my graphics adapter but I can continue with minimal graphics and give me the command line . My question is that how do I install through a text or if there is any way to fix this problem to run the graphical mode and so can continue the installation of Ubuntu, and if once installed Ubuntu the problem will be fixed or what? I would appreciate if you help me , as I mentioned before, there is almost nothing of Ubuntu but I think it will be easier than trying to get the Mac OS X proper . Spend good.

    Read the article

  • Pseudo random numbers in php

    - by pg
    I have a function that outputs items in a different order depending on a random number. for example 1/2 of the time Popeye's and its will be #1 on the list and Taco Bell and its logo will be #2 and half the time the it will be the other way around. The problem is that when a user reloads or comes back to the page, the order is re-randomized. $Range here is the number of items in the db, so it's using a random number between 1 and the $range. $random = mt_rand(1,$range); for ($i = 0 ; $i < count($variants); $i++) { $random -= $variants[$i]['weight']; if ($random <= 0) { $chosenoffers[$tag] = $variants[$i]; break; } } I went to the beginning of the session and set this: if (!isset($_SESSION['rannum'])){ $_SESSION['rannum']=rand(1,100); } With the idea that I could replace the mt_rand in the function with some sort of pseudo random generator that used the same 1-100 random number as a seed throughout the session. That way i won't have to rewrite all the code that was already written. Am I barking up the wrong tree or is this a good idea?

    Read the article

  • HOW TO SElect line number in TextBox Multiline

    - by Alhambra Eidos
    Hi all, I have large text in System.Windows.Forms.TextBox control in my form (winforms), vs 2008. I want find a text, and select the line number where I've found that text. Sample, I have fat big text, and I find "ERROR en línea", and I want select the line number in textbox multiline. string textoLogDeFuenteSQL = @"SQL*Plus: Release 10.1.0.4.2 - Production on Mar Jun 1 14:35:43 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. ** MORE TEXT **** Conectado a: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, Data Mining and Real Application Testing options WHERE LAVECODIGO = 'CO_PREANUL' * ERROR en línea 2: ORA-00904: ""LAVECODIGO"": identificador no v?lido INSERT INTO COM_CODIGOS * ERROR en línea 1: ORA-00001: restricción única (XACO.INX_COM_CODIGOS_PK) violada"; ** MORE TEXT **** Any sample code about it ? thanks in advanced,

    Read the article

  • how to read the txt file from the database(line by line)

    - by Ranjana
    i have stored the txt file to sql server database . i need to read the txt file line by line to get the content in it. my code : DataTable dtDeleteFolderFile = new DataTable(); dtDeleteFolderFile = objutility.GetData("GetTxtFileonFileName", new object[] { ddlSelectFile.SelectedItem.Text }).Tables[0]; foreach (DataRow dr in dtDeleteFolderFile.Rows) { name = dr["FileName"].ToString(); records = Convert.ToInt32(dr["NoOfRecords"].ToString()); bytes = (Byte[])dr["Data"]; } FileStream readfile = new FileStream(Server.MapPath("txtfiles/" + name), FileMode.Open); StreamReader streamreader = new StreamReader(readfile); string line = ""; line = streamreader.ReadLine(); but here i have used the FileStream to read from the Particular path. but i have saved the txt file in byt format into my Database. how to read the txt file using the byte[] value to get the txt file content, instead of using the Path value.

    Read the article

  • javascript turn single line break to double line break

    - by Eric Sim
    Hm... I'm trying to convert single line break into double line break, as in This is a sentence. This is another sentence. into This is a sentence. This is another sentence. Apparently this doesn't work ThisContent = ThisContent.replace(/(\n)/gm, "\n\n"); since it replace everything, including double line breaks. What's the regex to do this?

    Read the article

  • How to get surrounding method in Java source file for a given line number

    - by roesslerj
    I have a line number of a Java source file and want to get the sourounding method for that line number programatically. I looked into ANTLR which didn't help me much. Janino (http://www.janino.net) seems promising, I would scan and parse (and if necessary compile) the code. Then I could use JDI and ReferenceType.locationsOfLine(int lineNumber) Still I don't know how to use JDI for doing this and didn't find a tutorial that goes anywhere in this direction. Maybe there is some other way that I am completely missing.

    Read the article

  • C: Random Number Generation - What (If Anything) Is Wrong With This

    - by raoulcousins
    For a simple simulation in C, I need to generate exponential random variables. I remember reading somewhere (but I can't find it now, and I don't remember why) that using the rand() function to generate random integers in a fixed range would generate non-uniformly distributed integers. Because of this, I'm wondering if this code might have a similar problem: //generate u ~ U[0,1] u = ( (double)rand() / ((double)(RAND_MAX)); //inverse of exponential CDF to get exponential random variable expon = -log(1-u) * mean; Thank you!

    Read the article

  • Reading from a file not line-by-line

    - by MadH
    Assigning a QTextStream to a QFile and reading it line-by-line is easy and works fine, but I wonder if the performance can be inreased by first storing the file in memory and then processing it line-by-line. Using FileMon from sysinternals, I've encountered that the file is read in chunks of 16KB and since the files I've to process are not that big (~2MB, but many!), loading them into memory would be a nice thing to try. Any ideas how can I do so? QFile is inhereted from QIODevice, which allows me to ReadAll() it into QByteArray, but how to proceed then and divide it into lines?

    Read the article

  • Help with float numbers in Java

    - by Alvin
    Hi, Could anyone please me why the output of the following programme is not " different different"? public static void main(String[] args) { float f1=3.2f; float f2=6.5f; if(f1==3.2) System.out.println("same"); else System.out.println("different"); if(f2==6.5) System.out.println("same"); else System.out.println("different"); } o/p :different same

    Read the article

  • VB.net Need Text Box to Only Accept Numbers

    - by Rico Jackson
    I'm fairly new to VB.net (self taught) and was just wondering if someone out there could help me out with some code. I'm not trying to do anything to invovled, just have a textbox that takes numeric value from 1 to 10. I don't want it to take a string or any number above 10. If some types a word or character an error message will appear, telling them to enter a valid number. This is what I have, obviously it's not great as I am having problems. Thanks again to anyone who can help. If TxtBox.Text > 10 Then MessageBox.Show("Please Enter a Number from 1 to 10") TxtBox.Focus() ElseIf TxtBox.Text < 10 Then MessageBox.Show("Thank You, your rating was " & TxtBox.Text) Total = Total + 1 ElseIf IsNumeric(TxtBox.Text) Then MessageBox.Show("Thank you, your rating was " & ValueTxtBox.Text) End If ValueTxtBox.Clear() ValueTxtBox.Focus()

    Read the article

  • Eclipse Subversive revision numbers on multiple project commit

    - by CannyDuck
    If I have 2 projects in Eclipse that refers to the same repository location. repository location: svn://server project-module1 - svn://server/trunk/project-module1 project-module2 - svn://server/trunk/project-module2 So if I sync the project change with Subversive and have a change in module1 and module2 that refers to the same context I select all files and perform one commit, but if I look into my project revisions after that I see that 2 revisions were created. One for module1 and one for module2 with the same comment. How can I change the behave that only one revision number is created?

    Read the article

  • read text file line by line and insert/update values in table

    - by I__
    i am exploring the option of whether DoCmd.TransferText will do what i need, and it seems like it wont. i need to insert data if it does not exist and update it if it does exist i am planning to read a text file line by line like this: Dim intFile As Integer Dim strLine As String intFile = FreeFile() Open myFile For Input As #intFile Line Input #intFile, strLine Close #intFile i guess each individual line will be a record. it will probably be comma separated and some fields will have a " text qualifier because within the field itself i will have commas my question is how would i read a comma delimited text file that has double quotes sometimes as text qualifiers into a table in access?

    Read the article

  • Perl - Reading .txt files line-by-line and using compare function (printing non-matches only once)

    - by Kurt W
    I am really struggling and have spent about two full days on this banging my head against receiving the same result every time I run this perl script. I have a Perl script that connects to a vendor tool and stores data for ~26 different elements within @data. There is a foreach loop for @data that breaks the 26 elements into $e-{'element1'), $e-{'element2'), $e-{'element3'), $e-{'element4'), etc. etc. etc. I am also reading from the .txt files within a directory (line-by-line) and comparing the server names that exist within the text files with what exists in $e-{'element4'}. The Problem: Matches are working perfectly and only printing one line for each of the 26 elements when there is a match, however non-matches are producing one line for every entry within the .txt files (37 in all). So if there are 100 entries (each entry having 26 elements) stored within @data, then there are 100 x 37 entries being printed. So for every non-match in the: if ($e-{'element4'} eq '6' && $_ =~ /$e-{element7}/i) statement below, I am receiving a print out saying that there is not a match. 37 entries for the same identical 26 elements (because there are 37 total entries in all of the .txt files). The Goal: I need to print out only 1 line for each unique entry (a unique entry being $e-{element1} thru $e-{element26}). It is already printing one 1 line for matches, but it is printing out 37 entries when there is not a match. I need to treat matches and non-matches differently. Code: foreach my $e (@data) { # Open the .txt files stored within $basePath and use for comparison: opendir(DIRC, $basePath . "/") || die ("cannot open directory"); my @files=(readdir(DIRC)); my @MPG_assets = grep(/(.*?).txt/, @files); # Loop through each system name found and compare it with the data in SC for a match: foreach(@MPG_assets) { $filename = $_; open (MPGFILES, $basePath . "/" . $filename) || die "canot open the file"; while(<MPGFILES>) { if ($e->{'element4'} eq '6' && $_ =~ /$e->{'element7'}/i) { ## THIS SECTION WORKS PERFECTLY AND ONLY PRINTS MATCHES WHERE $_ ## (which contains the servernames (1 per line) in the .txt files) ## EQUALS $e->{'element7'}. print $e->{'element1'} . "\n"; print $e->{'element2'} . "\n"; print $e->{'element3'} . "\n"; print $e->{'element4'} . "\n"; print $e->{'element5'} . "\n"; # ... print $e->{'element26'} . "\n"; } else { ## **THIS SECTION DOES NOT WORK**. FOR EVERY NON-MATCH, THERE IS A ## LINE PRINTED WITH 26 IDENTICAL ELEMENTS BECAUSE ITS LOOPING THRU ## THE 37 LINES IN THE *.TXT FILES. print $e->{'element1'} . "\n"; print $e->{'element2'} . "\n"; print $e->{'element3'} . "\n"; print $e->{'element4'} . "\n"; print $e->{'element5'} . "\n"; # ... print $e->{'element26'} . "\n"; } # End of 'if ($e->{'element4'} eq..' statement } # End of while loop } # End of 'foreach(@MPG_assets)' } # End of 'foreach my $e (@data)' I think I need something to identical unique elements and define what fields make up a unique element but honestly I have tried everything I know. If you would be so kind to provide actual code fixes, that would be wonderful because I am headed to production with this script quite soon. Also. I am looking for code (ideally) that is very human-readable because I will need to document it so others can understand. Please let me know if you need additional information.

    Read the article

  • Get 100 highest numbers from an infinite list

    - by Sachin Shanbhag
    One of my friend was asked this interview question - "There is a constant flow of numbers coming in from some infinite list of numbers out of which you need to maintain a datastructure as to return the top 100 highest numbers at any given point of time. Assume all the numbers are whole numbers only." This is simple, you need to keep a sorted list in descending order and keep a track on lowest number in that list. If new number obtained is greater than that lowest number then you have to remove that lowest number and insert the new number in sorted list as required. Then question was extended - "Can you make sure that the Order for insertion should be O(1)? Is it possible?" As far as I knew, even if you add a new number to list and sort it again using any sort algorithm, it would by best be O(logn) for quicksort (I think). So my friend told it was not possible. But he was not convinced, he asked to maintain any other data structure rather than a list. I thought of balanced Binary tree, but even there you will not get the insertion with order of 1. So the same question I have too now. Wanted to know if there is any such data structure which can do insertion in Order of 1 for above problem or it is not possible at all.

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >