count the lines in a text/csv file.

Can you advice me how can I get the total number of lines in a text/CSV file please using java code.

I will get the contents of the text/csv file in a string variable to no not as a file.

EX: string var = "123\n234\n123\n3456\nsdfsd\n" this is \n in the new line.

for that I have to get the total rows 5.

Please advice.

Thank you.

I think I have to try a split of the string and see how big the table is either simply to count the number of newline characters. Since you said you have a huge file and your data are contained in 1 chain, then you should be able to do it more conveniently.

Tags: Java

Similar Questions

  • How to concatenate strings with the lines of a text file

    Hello
    I tried concatenate strings with the lines of a text file, but something is wrong with my code and I belive is the agruments I use in the cycle for. If anyone can help me I will appreciate it very much.
    My code is:
    [code]@echo off
    the value "input=C:\Users\123\Desktop\List.txt".
    for /f "usebackq tokens = *" % in (' input % ') do)
    the value 'str1 = C:\some directory\ ".
    the value ' str2 = %% ~ F '.
    the value "str3 = .pdf".
    the value "str4 = str1% str2% str3%.
    echo.%STR4%
    ) [/ code]
    and the text file is something like:
    121122 [code]
    122233
    123344
    124455 [/ code]
    But I get only one wrong answer and I have to run it like 3 times to get a real result and it is a mistake, the first two are empty spaces and gives the third one as the last line of the text file but repeated n times, where n is the number of lines in the text file.
    Result:
    [code] C:\Users\123\Desktop>concatenate.bat
    C:\Users\123\Desktop>concatenate.bat
    C:\Users\123\Desktop>concatenate.bat
    C:\some directory\124455.pdf
    C:\some directory\124455.pdf
    C:\some directory\124455.pdf
    C:\some directory\124455.pdf
    C:\some directory\124455.pdf
    C:\Users\123\Desktop>[/code]
    So if anyone has an idea about what is wrong please let me know.
    Concerning
    -Victor-

    Hi Victor,

    This forum is dedicated to the support of the Office of consumer Windows (fonts, colors, personal settings).  Since your question is about programming and usually outside the context of most of the customers, I suggest you post your question in the forums as http://msdn.microsoft.com - the Microsoft network to users will be more adapted to help you in your quest.
  • I need to export the address book in unicode csv files. When?

    My address book contains Chinese and Korean names. Their special characters get lost when I export the address book to a CSV files to import them from Open Office.

    It is true that Chinese and Korean characters are not maintained when you use the export into csv format, but I tried an example with the option provided by MoreFunctionsForAddressBook and it seems to work fine.

    Select an address book in the address book, then make a right click, MFFAB/Export/as csv (.csv).

  • Why can't I edit (cut the lines/words/phrases) in PDF files on my laptop. I even downloaded a software, but are still unable to edit?

    I want to know that I can not change (cut the lines/words/phrases) in PDF files on my laptop... can u help please...

    I have downloaded even hv a software, impossible to do?

    Hello Jonathan New Zealand,.

    Addition information of Santosh, please let me explain further.
    If you have only downloaded a PDF reader software as Adobe Reader which can be downloaded for free, you can only read the file you cannot change the file. You need to download or buy PDF Editor so you can edit and read the PDF file.

    Hope this explains a little further.

    Marilyn

  • How to export a form that has the Asian language in to CSV file? Currently the CSV file shows [...] for the characters of Asian languages

    How to export a form that has the Asian language in to CSV file? Currently the CSV file shows [...] for the characters of Asian languages

    If you export as XML instead, it should work because it uses UTF - 8.

  • Use the lines of a text file as input to an SQL command

    Hello

    I have a text file containing the lines...

    123

    1234

    I would like to use as input for a SQL command running in a script. ie

    Update flag set < table > = 'Y' where job = < the text file lines >;

    Any help much appreciated.

    See you soon

    External table will do.

    For reference...

    CREATE TABLE Hold'em (SEQ_NUM NUMBER (10));

    insertion in hold select SEQ_NUM in task where proc like '% PROC;

    update set hold_flag = task ' ' where in SEQ_NUM (select hold SEQ_NUM);

  • Remove the last comma before reading csv files

    Hello

    I'm working on a VI that reads a lot of files csv (created by an application) using the built-in "worksheet File.vi reading" before combining in a report by using the excel report generation tool. 'All lines' are read in the csv file by using the worksheet File.vi reading.

    There are cases of csv files, where there an unwanted comma to the end of the line and an extra cell (with no data) appears in the final report. I was wondering if there is an easy way to remove it (rather than passing through each line and get rid of it).

    Thank you!

    You will need to go through each line, look at the last element and delete it if it is an empty string.  But a loop, it's easy:

    Read the spreadsheet, get 2D array of strings.  For each line, download the last element.  Test if she is a Virgin.  If so, remove it from the table.  If this is not the case, switch the blank table.

  • Insert the new value in existing csv file

    Hello

    I have a CSV file that I created using a totalizer. now I need to insert this string values by searching the line

    For example:-first column is date so I'll look for the date and insert comment for her

    attached the CSV file


  • Export the properties of the virtual computer in a CSV file

    Hi all

    I found a powercli script in the community forum and modified it a bit.  What I want to do is, I want to get the VM by CLUSTER properties and export the properties selected to CSV file then send it. When I run the script I see three different properties on the screen (Write-Host $Report) but when I look at the csv file I only see a VM entry rather then three.  Here's what I have so far;

    1. # Name of the VMware VirtualCenter Server

    ####################################

    $vcserver = "localhost".

    ##################

    1. Add VI-box #.

    ##################

    Add-PSsnapin VMware.VimAutomation.Core

    Initialize - VIToolkitEnvironment.ps1

    to connect-VIServer $vcserver

    ##################

    1. Send variables #.

    ##################

    $enablemail = 'no '.

    $smtpServer = "mymailserver.com".

    $mailfrom = "test VMware status & lt; . [email protected] & gt; »

    $mailto = " " [email protected] "" "

    #############

    1. Variables #.

    #############

    $filelocation="D:\temp\healthcheck.csv".

    $date = get-date

    #############################

    1. Get - VM Information. #

    #############################

    Get - VM | `

    {ForEach-Object

    $VM = $_

    $VMview = $VM | Get-View

    $VMResourceConfiguration = $VM | Get-VMResourceConfiguration

    $VMHardDisks = $VM | Get-hard drive

    $HardDisksSizesGB = @)

    $Temp = $VMHardDisks | ForEach-Object {$HardDisksSizesGB += : tour ($_.)} (CapacityKB/1Mo)}

    $VmdkSizeGB = «»

    $Temp = $HardDisksSizesGB | ForEach-Object {$VmdkSizeGB = "$_" "'}

    $VmdkSizeGB = $VmdkSizeGB.TrimEnd("+")

    $TotalHardDisksSizeGB = 0

    $Temp = $HardDisksSizesGB | ForEach-Object {$TotalHardDisksSizeGB += $_}

    $Snapshots = $VM | Get-Snapshot

    $Report = "" | Select-Object VMname,ESXname,ClusterName,MemoryGB,vCPUcount,vNICcount,IPaddresses,VmdkSizeGB,TotalVmdkSizeGB,DatastoreName,ToolsVersion,ToolsUpdate,NumCpuShares,CpuLimitMHZ,CpuReservationMHZ,NumMemShares,ReservationsMB,LimitMB,SnapshotCount,GuestOS

    $Report.VMName = $VM.name

    $Report.ESXname = $VM. Host

    $Report.ClusterName = ($VM |) Get - Cluster). Name

    $Report.MemoryGB = $VM. MemoryMB/1024

    $Report.vCPUcount = $VM. NumCpu

    $Report.vNICcount = $VM. Guest.Nics.Count

    $Report.IPaddresses = $VM. Guest.IPAddress

    $Report.VmdkSizeGB = $VmdkSizeGB

    $Report.TotalVmdkSizeGB = $TotalHardDisksSizeGB

    $Report.DatastoreName = $VMview.Config.DatastoreUrl

    $Report.ToolsVersion = $VMview.Config.Tools.ToolsVersion

    $Report.ToolsUpdate = $VMview.Guest.ToolsStatus

    $Report.NumCpuShares = $VMResourceConfiguration.NumCPUShares

    $Report.CpuLimitMHZ = $VMResourceConfiguration.CpuLimitMhz

    $Report.CpuReservationMHZ = $VMResourceConfiguration.CpuReservationMhz

    $Report.NumMemShares = $VMResourceConfiguration.NumMemShares

    $Report.ReservationsMB = $VMResourceConfiguration.MemReservationMB

    $Report.LimitMB = $VMResourceConfiguration.MemLimitMB

    $Report.SnapshotCount = (@($VM |) Get - Snapshot)). County

    $Report.GuestOS = $VM. Guest.OSFullName

    Write-Host $Report

    $Report | where-object {$_.} NOMCLUSTER - eq "Test_Cluster"} | Select-Object - property NOMCLUSTER, ESXName, VCPUCount, Memorygb, Vmname | Tri - ESXName of property | Export-csv "$filelocation" - NoTypeInformation

    }

    If ($enablemail - corresponds to 'Yes')

    {

    $msg = new-object Net.Mail.MailMessage

    $att = new-object Net.Mail.Attachment ($filelocation)

    $smtp = new-object Net.Mail.SmtpClient ($smtpServer)

    $msg. From = $mailfrom

    $msg. To.Add ($mailto)

    $msg. Object = "check the status of VMware.

    $msg. Body = "check the status of VMware.

    $msg. Attachments.Add ($att)

    $smtp. Send ($MSG)

    }

    Any help much appreciated.

    Change this section:

    Get-VM | `
    ForEach-Object {
    $VM = $_
    $VMview = $VM | Get-View
    $VMResourceConfiguration = $VM | Get-VMResourceConfiguration
    $VMHardDisks = $VM | Get-HardDisk
    $HardDisksSizesGB = @()
    $Temp = $VMHardDisks | ForEach-Object { $HardDisksSizesGB += Math::Round($_.CapacityKB/1MB) }
    $VmdkSizeGB = ""
    $Temp = $HardDisksSizesGB | ForEach-Object { $VmdkSizeGB = "$_" }
    $VmdkSizeGB = $VmdkSizeGB.TrimEnd("+")
    $TotalHardDisksSizeGB = 0
    $Temp = $HardDisksSizesGB | ForEach-Object { $TotalHardDisksSizeGB += $_ }
    $Snapshots = $VM | Get-Snapshot
    $Report = "" | Select-Object VMname,ESXname,ClusterName,MemoryGB,vCPUcount,vNICcount,IPaddresses,VmdkSizeGB,TotalVmdkSizeGB,DatastoreName,ToolsVersion,ToolsUpdate,NumCpuShares,CpuLimitMHZ,CpuReservationMHZ,NumMemShares,ReservationsMB,LimitMB,SnapshotCount,GuestOS
    $Report.VMName = $VM.name
    $Report.ESXname = $VM.Host
    $Report.ClusterName = ($VM | Get-Cluster).Name
    $Report.MemoryGB = $VM.MemoryMB/1024
    $Report.vCPUcount = $VM.NumCpu
    $Report.vNICcount = $VM.Guest.Nics.Count
    $Report.IPaddresses = $VM.Guest.IPAddress
    $Report.VmdkSizeGB = $VmdkSizeGB
    $Report.TotalVmdkSizeGB = $TotalHardDisksSizeGB
    $Report.DatastoreName = $VMview.Config.DatastoreUrl
    $Report.ToolsVersion = $VMview.Config.Tools.ToolsVersion
    $Report.ToolsUpdate = $VMview.Guest.ToolsStatus
    $Report.NumCpuShares = $VMResourceConfiguration.NumCPUShares
    $Report.CpuLimitMHZ = $VMResourceConfiguration.CpuLimitMhz
    $Report.CpuReservationMHZ = $VMResourceConfiguration.CpuReservationMhz
    $Report.NumMemShares = $VMResourceConfiguration.NumMemShares
    $Report.ReservationsMB = $VMResourceConfiguration.MemReservationMB
    $Report.LimitMB = $VMResourceConfiguration.MemLimitMB
    $Report.SnapshotCount = (@($VM | Get-Snapshot)).Count
    $Report.GuestOS = $VM.Guest.OSFullName
    Write-Host $Report
    $Report | where-object {$_.ClusterName -eq "Test_Cluster"} | Select-Object -Property ClusterName,ESXName,Vmname,Memorygb,VCPUCount | sort -Property ESXName | Export-csv "$filelocation" -NoTypeInformation
    }
    

    To do this:

    $NewObject = @()
    Get-VM | `
    ForEach-Object {
    $VM = $_
    $VMview = $VM | Get-View
    $VMResourceConfiguration = $VM | Get-VMResourceConfiguration
    $VMHardDisks = $VM | Get-HardDisk
    $HardDisksSizesGB = @()
    $Temp = $VMHardDisks | ForEach-Object { $HardDisksSizesGB += Math::Round($_.CapacityKB/1MB) }
    $VmdkSizeGB = ""
    $Temp = $HardDisksSizesGB | ForEach-Object { $VmdkSizeGB = "$_" }
    $VmdkSizeGB = $VmdkSizeGB.TrimEnd("+")
    $TotalHardDisksSizeGB = 0
    $Temp = $HardDisksSizesGB | ForEach-Object { $TotalHardDisksSizeGB += $_ }
    $Snapshots = $VM | Get-Snapshot
    $Report = "" | Select-Object VMname,ESXname,ClusterName,MemoryGB,vCPUcount,vNICcount,IPaddresses,VmdkSizeGB,TotalVmdkSizeGB,DatastoreName,ToolsVersion,ToolsUpdate,NumCpuShares,CpuLimitMHZ,CpuReservationMHZ,NumMemShares,ReservationsMB,LimitMB,SnapshotCount,GuestOS
    $Report.VMName = $VM.name
    $Report.ESXname = $VM.Host
    $Report.ClusterName = ($VM | Get-Cluster).Name
    $Report.MemoryGB = $VM.MemoryMB/1024
    $Report.vCPUcount = $VM.NumCpu
    $Report.vNICcount = $VM.Guest.Nics.Count
    $Report.IPaddresses = $VM.Guest.IPAddress
    $Report.VmdkSizeGB = $VmdkSizeGB
    $Report.TotalVmdkSizeGB = $TotalHardDisksSizeGB
    $Report.DatastoreName = $VMview.Config.DatastoreUrl
    $Report.ToolsVersion = $VMview.Config.Tools.ToolsVersion
    $Report.ToolsUpdate = $VMview.Guest.ToolsStatus
    $Report.NumCpuShares = $VMResourceConfiguration.NumCPUShares
    $Report.CpuLimitMHZ = $VMResourceConfiguration.CpuLimitMhz
    $Report.CpuReservationMHZ = $VMResourceConfiguration.CpuReservationMhz
    $Report.NumMemShares = $VMResourceConfiguration.NumMemShares
    $Report.ReservationsMB = $VMResourceConfiguration.MemReservationMB
    $Report.LimitMB = $VMResourceConfiguration.MemLimitMB
    $Report.SnapshotCount = (@($VM | Get-Snapshot)).Count
    $Report.GuestOS = $VM.Guest.OSFullName
    $NewObject += $Report
    }
    $NewObject | where-object {$_.ClusterName -eq "Test_Cluster"} | Select-Object -Property ClusterName,ESXName,Vmname,Memorygb,VCPUCount | sort -Property ESXName | Export-csv "$filelocation" -NoTypeInformation
    

    Chris Nakagaki (Zsoldier)

    http://tech.zsoldier.com

    Post edited by: Zsoldier

  • Basic question on the lines in a text box

    How do you get a stroke in a text box to automatically extend at the edge of the box?

    If I could control the length of the lines as below just by resizing the text box.

    2009-05-11_122901.png

    I know this is possible because I saw him in the old Pagemaker files.

    Use a right-indent tab and apply underscore tab.

  • Why are the lines of my text-images "off"?

    Hello.

    I have a number of images text threaded at the other. tfLK [0] (the first in an array of managers of related texts) a (visually) lines 29 , but ' $.writeln(tfLK[0].lines.length) ' returns to 33, and indeed, when I target 'tfLK [0].lines.items (32) "I get the 4th line on the second image. Like-Wise, when I target ".lines.items (32) tfLK [1] ' (the second image of the thread), I get the 4th line of the third image. "

    What is going on?

    Can I fix?

    Any help would be appreciated.

    I get an error in ESTK

    Same thing.

    I found my mistake. I had reduced the first block of text of the wire after the search of line number, that's why I got the wrong results.

    Thanks for trying to help

  • Export of objects of the inventory of VC to CSV files

    Can someone help me develop the following script? I would create five CSV files, one file for each of the following objects in a VC inventory specified:

    1. data centers - name, location (e.g., the children of a folder / root?)

    2. cluster - name, location (e.g., the children of a folder / data center?), DRS enabled?, DRS, HA mode?

    3. records - name, location (e.g., the children of a folder / data center / root?)

    4. host - name, location (e.g., the children of a folder / data center?), clustered?

    5. resource Pools - name, location (e.g., children of a cluster / resource pool), information sharing

    This will be useful for a "backup" of the inventory of VC human readable.

    I tried to use Get-inventory but have problems with collecting the parent / child relationships and filter objects by default (for example, root data center, resource pool "resources", etc.)

    Any help is appreciated. Thank you.

    Take a look at this document.

    Contains export and import functions

    http://communities.VMware.com/docs/doc-12182

    -

  • count the words in a text widget

    Hello

    Is there a way I can count the number of words in a text box widget?  I realize that means counting the number of words in the attached variable - but can I do this?

    I tried to play with Javascript (which I know nothing)

    I put the following script in the script for a button pane, but nothing seems to happen!

    Test = Q5WidgetAnswer.Split (""). Length-1;

    document. Write (test);

    I want to check three words in a response, and if there are only two, or four, warns that there are three answers.

    Would be grateful for any help!

    After a lot of grief, I solved the problem.

    The code should be as follows:

    var objCP = document. Captivate;
    Var response = objCP.cpEIGetValue ('WidgetAnswer');
    Var words;

    if(Answer == '') {/ * empty response tests * /}
    Words = 0;
    Alert("Fred")

    }
    else {}

    Words = Answer.replace(/[^]/g,'').length + 1;    / * counts the number of places in response * /.

    }

    Where objCP can be any name that you want, and cpEISetValue and cpEIGetValue are special features of Captivate

    / * and * / add a comment

  • Count the lines in a list component

    Hello

    How can I count the rows with a value in a list item?

    I thought it would be RowCount but as I understood that shows the number of specified rows, not the number of rows with a value.

    Hello

    Try list.dataProvider.length

  • What is the line outside my text box?

    Can someone help me please understand that this lighter blue line is above the text box? It seems to be an extension of the text box, or a spacer/padding? I was given this file by another designer and unforunately, I'm not familiar with this feature. I would use it in the future - remove/change/add - to text boxes...  Thank you!!!

    Screen Shot 2015-06-05 at 12.14.05 PM.png

    I guess you see a text wrap the area where the skin is attached to:
    the values of left, right, down: 0

    top: the amount that you recognize as 'thin blue line '.

    Like this (German UI):

    Uwe

Maybe you are looking for