How to count the number of lines in a file using Bash?
Let’s learn how to count the number of lines in a file using Bash. The most accurate or helpful solution is served by Stack Overflow.
There are ten answers to this question.
Best solution
I can do this easily in python or some other high level language. What I am interested in is doing this with bash. Here is the file format: head-xyz item1 item2 item3 head-abc item8 item5 item6 item9 What I would like to do is print the following output: head-xyz: 3 head-abc: 4 header will have a specific pattern similar to the example i gave above. items also have specific patterns like in the example above. I am only interested in the count of items under each header.
Answer:
You can use awk: awk '/head/{h=$0}{c[h]++}END{for(i in c)print i, c[i]-1}' input.file
powerrox at Stack Overflow Mark as irrelevant Undo
Other solutions
Answer:
Use the following: awk 'END { print NR }' Awk will count the lines and print it out.
wiki.answers.com Mark as irrelevant Undo
Imports System.IO Public Class Form1 Public Structure ExamGrades Dim name As String Dim grade As Integer End Structure Dim Values() As String Dim Count As String = 0 Dim grades As New List(Of ExamGrades) Private Sub Form1_Load(ByVal sender As System...
Answer:
If you go an easy way, you can create a one-dimensional array (each element is string like this: &ldquo...
Petro at Yahoo! Answers Mark as irrelevant Undo
Hi, I am creating a program that calculates the distance between the x, y, z coordinates of atoms listed in a pdb file. So far i have this: #!/usr/bin/perl -w $num = 0; $count = 0; while (<>) { # Find x, y, z coordinates and store in separate arrays...
Answer:
First of all, add the following to the top of your program, it's common courtesy BEFORE coming here...
monica at Yahoo! Answers Mark as irrelevant Undo
'sed' is taking a lot of time.
Answer:
As i know there is no kernel support for changing the start position of a file in place, you still have...
Jimmy Wennlund at Quora Mark as irrelevant Undo
Answer:
wc -l wc stands for "word count". The -l switch (that's a lower case "L") is to...
Freedom at Yahoo! Answers Mark as irrelevant Undo
Anonymous at ChaCha Mark as irrelevant Undo
Eunji Choi at Quora Mark as irrelevant Undo
QUESTION: Thanks for your help I finally managed to make all the changes and now it's working fine. Could you please help me so that when the user clicks the button it opens the file automatically using a file location rather than "FD" File...
Answer:
Srinivasa, Thank you for the more thorough explanation. I will study tomorrow and try to offer a solution...
Miningco.com Mark as irrelevant Undo
QUESTION: Here is my program. I cannot get it to work ..following that are the instructions..any advice would be appreciated using namespace std; // function prototypes void calculateAverage (ifstream&, ofstream& , double&); void calculateGrade...
Answer:
Hello Jason Well, I think I got the output you want. I had to change many of the setw calls, and left...
Miningco.com Mark as irrelevant Undo
Related Q & A:
- How to upload a file to another server using cURL and PHP?Best solution by Stack Overflow
- How to cancel a file upload using an iframe?Best solution by Stack Overflow
- How to count number of occurrences of pattern within a string?Best solution by Stack Overflow
- How to Count total number of Words in PDF?Best solution by Super User
- How to search for a particular string in a text file using java?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.