count number of characters in line 
Author Message
 count number of characters in line

Hi everyone.

After having wrestled with the awk man page for some time, I have still been
unable to find the solution to a particular problem I have. I was hoping
someone here could help me out a bit.

I have a file which looks somewhat like this:

foo:barfoo:blah:duh:bar:
foo:blahblah:foo
foo:blahblah:huh:bar:foo:duh:foo:bar

For each line in this file, I whish to count the number of characters in
each line, including spaces and other 'funny' characters. If the amount of
characters exceeds a certain number (say 1024 characters) I need to print
both the line itself and the line number to stdout.

Now I know that this has got to be just the kind of stuff awk was designed
to do, if I could only figure out how...

Sincerely,

J.Smith



Sat, 10 Jan 2004 02:19:50 GMT  
 count number of characters in line
The length of the current line can be found as length($0), so that

length($0) > 1024 { print NR":", $0; }

should do it.

Aloha,
Brad

Quote:

> Hi everyone.

> After having wrestled with the awk man page for some time, I have still been
> unable to find the solution to a particular problem I have. I was hoping
> someone here could help me out a bit.

> I have a file which looks somewhat like this:

> foo:barfoo:blah:duh:bar:
> foo:blahblah:foo
> foo:blahblah:huh:bar:foo:duh:foo:bar

> For each line in this file, I whish to count the number of characters in
> each line, including spaces and other 'funny' characters. If the amount of
> characters exceeds a certain number (say 1024 characters) I need to print
> both the line itself and the line number to stdout.

> Now I know that this has got to be just the kind of stuff awk was designed
> to do, if I could only figure out how...

> Sincerely,

> J.Smith



Sat, 10 Jan 2004 02:55:47 GMT  
 count number of characters in line


Quote:
> The length of the current line can be found as length($0), so that

> length($0) > 1024 { print NR":", $0; }

> should do it.

It does.
:)

Thanks very much for the help.



Sat, 10 Jan 2004 03:37:46 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to count number of characters in string?

2. max number of characters and continuation lines

3. Counting commented lines (full-line comments only)

4. how to split each new line into a list, considering quoted new line characters

5. Reading unknown number of lines in unknown number of files

6. Question: lines of numbers separated with empty lines

7. text widget, how to get line number of first line displayed

8. How to count characters?

9. Characters count in RTF Text

10. HELP! counting characters in AWK

11. Simulating non-standard Q character count edit descriptor

12. How to count substring of a main string of character

 

 
Powered by phpBB® Forum Software