How to count number of characters of wc -l output?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to count number of characters of wc -l output?
# 1  
Old 10-13-2014
How to count number of characters of wc -l output?

I want count number of characters / find the length of the 'wc -l' output

This is the command

Code:
bash-3.2$ gzcat /home/sid/file1.dat |wc -l
  830752

So final out I want is 6 i.e lenght of 830752

I tried with awk
Code:
bash-3.2$ gzcat /home/sid/file1.dat |wc -l | awk '{print length ($0) }'
8

it gave me 8, possibly padding the first two characters.

Can someone help me achieve this?

Thanks
# 2  
Old 10-13-2014
See the man pages. wc. -l counts lines

the wc version on bash provides a -m, -c and -k switch to count characters.
# 3  
Old 10-13-2014
Quote:
Originally Posted by blackrageous
See the man pages. wc. -l counts lines

the wc version on bash provides a -m, -c and -k switch to count characters.
That doesnt solve my problem. I want the count of characters of the row count of all rows. Which means I need the count of wc -l
# 4  
Old 10-13-2014
Code:
 
wc -l  yourfile | awk -F" " '{print length($1)}'

still not sure what you are looking for

Code:
 
y=$(cat yourfile | wc -l)
echo "${#y}"


Last edited by senhia83; 10-13-2014 at 05:33 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count the number of string occurrences to display 0 entries in output

Hello Friends, Can somebody assist an issue I am having? I have a separate file with a list of account ids XXX200B02Y01 XXX200B03Y01 XXX200B05Y01 XXX200B07Y01 XXX200B08Y01 I call the file, and run an egrep against a directory and logfiles AccountID=$(cat... (2 Replies)
Discussion started by: liketheshell
2 Replies

2. Shell Programming and Scripting

Limit the number of characters in bash output

Hi, I need some help with this: I'm making a script which does a couple of things with image files. The script is supposed to echo the number of each image it is processing like this: Processing image1.jpgThe problem is with images with very long filenames, so I want to know how to limit the... (5 Replies)
Discussion started by: Shadow_Reaper
5 Replies

3. Shell Programming and Scripting

Count number of characters in particular column

Hi i have data like abchd 124 ldskc aattggcc each separated by tab space i want to count number of characters in 4th column and print it in new column with tabspace for every line can anyone help me how to do it. Thanks. (3 Replies)
Discussion started by: bhargavpbk88
3 Replies

4. UNIX for Dummies Questions & Answers

Limit the number of characters in a bash output

I have a script that outputs the weather on two lines. If possibly I would like to set a character limit on them Currently it outputs something like but I would like to limit the lines so appends an ellipsis if nescessary: This is the script #! /bin/bash curl -s --connect-timeout... (2 Replies)
Discussion started by: Light_
2 Replies

5. Shell Programming and Scripting

how to add the number of row and count number of rows

Hi experts a have a very large file and I need to add two columns: the first one numbering the incidence of records and the another with the total count The input file: 21 2341 A 21 2341 A 21 2341 A 21 2341 C 21 2341 C 21 2341 C 21 2341 C 21 4567 A 21 4567 A 21 4567 C ... (6 Replies)
Discussion started by: juelillo
6 Replies

6. UNIX for Dummies Questions & Answers

Unix command to count the number of files with specific characters in name

Hey all, I'm looking for a command that will search a directory (and all subdirectories) and give me a file count for the number of files that contain specific characters within its filename. e.g. I want to find the number of files that contain "-a.jpg" in their name. All the searching I've... (6 Replies)
Discussion started by: murphysm
6 Replies

7. Shell Programming and Scripting

count the number of lines that start with the number

I have a file with contents similar to this. abcd 1234 4567 7666 jdjdjd 89289 9382 92 jksdj 9823 298 I want to write a shell script which count the number of lines that start with the number (disregard the lines starting with alphabets) (1 Reply)
Discussion started by: grajp002
1 Replies

8. Programming

Count the number of repeated characters in a given string

i have a string "dfasdfasdfadf" i want to count the number of times each character is repeated.. For instance, d is repeated 4 times, f is repeated 4 times.. can u give a program in c (1 Reply)
Discussion started by: pgmfourms
1 Replies

9. Shell Programming and Scripting

Number count per number ranges

Hi, I have a question here that need to get advise from all of you. Let say I have a set of data 12347777 12359899 12347677 12360090 12347688 12359979 12359009 12367022 12346677 I need to count the number that appear in each numbering ranges and the output is like below: Prefix ... (5 Replies)
Discussion started by: shirleyeow
5 Replies

10. UNIX for Dummies Questions & Answers

Word Count without any characters but the Output String

Hi all, I am logging any access to a server, and i wanted to write a script which tells me how much entries there are. The Problem is that "wc -l log" outputs the correct number of lines but with the name of the file attached. is there any nice possibility to solve this that i ONLY... (3 Replies)
Discussion started by: JP_II
3 Replies
Login or Register to Ask a Question