Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Getting the character count of the last line Post 302739189 by Scrutinizer on Monday 3rd of December 2012 04:31:50 PM
Old 12-03-2012
Try:
Code:
find sent/ -type f -exec tail -1 {} \; | awk '{print length}'

To also count the linefeed at the end of the line, like wc -c or wc -m use awk '{print length+1}'



--
Use wc -c counts bytes, BTW. To count (multibyte) characters use wc -m

Last edited by Scrutinizer; 12-03-2012 at 06:27 PM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to count the occurence of a character in a line

Suppose i have data like :- 1,2,3,4,5 a,b,c x,y,z,t I want to count the occurence of , (comma) in every line. Waiting for a solution.:) (1 Reply)
Discussion started by: sumit207
1 Replies

2. UNIX for Dummies Questions & Answers

How to count the occurence of a character in a line

Suppose i have data like :- 1,2,3,4,5 a,b,c x,y,z,t I want to count the occurence of , (comma) in every line. Waiting for a solution. (5 Replies)
Discussion started by: sumit207
5 Replies

3. Shell Programming and Scripting

Looking for a single line to count how many times one character occurs in a word...

I've been looking on the internet, and haven't found anything simple enough to use in my code. All I want to do is count how many times "-" occurs in a string of characters (as a package name). It seems it should be very simple, and shouldn't require more than one line to accomplish. And this is... (2 Replies)
Discussion started by: Shingoshi
2 Replies

4. Shell Programming and Scripting

awk: sort lines by count of a character or string in a line

I want to sort lines by how many times a string occurs in each line (the most times first). I know how to do this in two passes (add a count field in the first pass then sort on it in the second pass). However, can it be done more optimally with a single AWK command? My AWK has improved... (11 Replies)
Discussion started by: Michael Stora
11 Replies

5. UNIX for Advanced & Expert Users

Count specific word or character per line

Hi, I need help regarding counting specific word or character per line and validate it against a specific number i.e 10. And if number of character equals the specific number then that line will be part of the output. Specific number = 6 Specific word or char = || Sample data:... (1 Reply)
Discussion started by: janzper
1 Replies

6. Shell Programming and Scripting

Count character in one line

Please check the attachment for the example. Purpose: count how many "|" character in one line and also display the line number. expect result: Line 1 : there are 473 "|" characters Line 2 : there are 473 "|" characters I have tried to use awk to count it, it's ok when the statistic... (8 Replies)
Discussion started by: ambious
8 Replies

7. Shell Programming and Scripting

Delete line based on count of specific character

I'm looking for what I hope might be a one liner along these lines: sed '/a line with more than 3 pipes in it/d' I know how to get the pipe count in a string and store it in a variable, but I'm greedy enough to hope that it's possible via regex in the /.../d context. Am I asking too much? ... (5 Replies)
Discussion started by: tiggyboo
5 Replies

8. UNIX for Dummies Questions & Answers

Script to count character present in a line

Suppose i have multiple line like below in a file. ASDFAFAGAHAHAHA AGAHAHAJGAFAGAH AHAHAKAHAHAHAKA I need a bash script to count a character and also Also count the number of character present in each line . suppose for line 1: A=x, S=y, D=x and so on and total character=15. where x y and z is... (3 Replies)
Discussion started by: XXLMMN
3 Replies

9. Shell Programming and Scripting

Character count of each line

Hi, I have a file with more than 1000 lines. Most of the lines have 16 characters. I want to find out lines that have less than 14 characters (usually 12 or 13). wc -l gives me the line count and wc -c gives me the total characters in a file. I could not get the total characters for each line.... (1 Reply)
Discussion started by: bobbygsk
1 Replies

10. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies
wc(1)								   User Commands							     wc(1)

NAME
wc - display a count of lines, words and characters in a file SYNOPSIS
/usr/bin/wc wc [-c | -m | -C] [-lw] [file]... ksh93 wc [-c | -m | -C] [-lLqw] [file]... DESCRIPTION
/usr/bin/wc wc reads one or more input files and, by default, writes the number of NEWLINE characters, words and bytes contained in each input file to the standard output. wc also writes a total count for all named files, if more than one input file is specified. wc considers a word to be a non-zero-length string of characters delimited by white space (for example, SPACE, TAB). See iswspace(3C) or isspace(3C). ksh93 The wc built-in in ksh93 is associated with the /bin and /usr/bin paths. It is invoked when wc is executed without a pathname prefix and the pathname search finds a /bin/wc or /usr/bin/wc executable. wc reads one or more input files and, by default, for each file writes a line containing the number of NEWLINEs, words, and bytes contained in each file followed by the file name to standard output in that order. A word is defined to be a non-zero length string delimited by iss- pace(3C) characters. If more than one file is specified, wc writes a total count for all of the named files with total written instead of the file name. By default, wc writes all three counts. Options can specified so that only certain counts are written. The -c, -C, and -m options are mutu- ally exclusive. If no file is specified, or if the file is -, wc reads from standard input and no filename is written to standard output. The start of the file is defined as the current offset. -c --bytes | chars List the byte counts. -l --lines List the line counts. -L --longest-line | max-line-length List the longest line length. -m | C --multibyte-chars List the character counts. -q --quiet Suppress invalid multi-byte character warnings. -w --words List the word counts. OPTIONS
The following options are supported: -c Counts bytes. -C Same as -m. -l Counts lines. -m Counts characters. -w Counts words delimited by white space characters or new line characters. Delimiting characters are Extended Unix Code (EUC) charac- ters from any code set defined by iswspace(). If no option is specified, the default is -lwc (counts lines, words, and bytes.) OPERANDS
The following operand is supported: file A path name of an input file. If no file operands are specified, the standard input is used. USAGE
See largefile(5) for the description of the behavior of wc when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of wc: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. EXIT STATUS
0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin/wc +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |Standard |See standards(5). | +-----------------------------+-----------------------------+ ksh93 +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |See below. | +-----------------------------+-----------------------------+ The ksh93 built-in binding to /bin and /usr/bin is Volatile. The built-in interfaces are Uncommitted. SEE ALSO
cksum(1), ksh93(1), isspace(3C), iswalpha(3C), iswspace(3C), setlocale(3C), attributes(5), environ(5), largefile(5), standards(5) SunOS 5.11 13 Mar 2008 wc(1)
All times are GMT -4. The time now is 03:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy