Computing.Net > Forums > Unix > Find length of each line in a file.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Find length of each line in a file.

Reply to Message Icon

Name: long_unix
Date: June 13, 2007 at 08:00:43 Pacific
OS: AIX
CPU/Ram: 512
Product: IBM
Comment:

Hi All,
I have a file, contains:
"jfd, jlk, slj, lsk, lskd, sldj, adk"
"sdj, lkdjf, lsdjfj, lsjf, kds, skldj, slk"
"kdj, kdsk, skd, skdk, sljs "
...
each line has quotes, spaces, commas and characters. I'd like to find the length of each line; include everything that contains in the line (", ',', space and characters). I've tried to use 'wc -c' command in the script but it did not work.

Thanks in Advance

Hi All,
I have a file contains several lines and each line has different length. In each line has a space. Here is a line in a file looks like:
"AAB, FFC, EEE, FEF, JKL, JJK"
"FDL, JLJ, KK



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 13, 2007 at 09:29:57 Pacific
Reply:

I think you just want to read each line and find the length:

#!/bin/ksh

while read line
do
echo ${#line} # echo the line length
done < myfile.tx


0

Response Number 2
Name: long_unix
Date: June 13, 2007 at 09:42:34 Pacific
Reply:

It works. Thank you so much.

Hi All,
I have a file contains several lines and each line has different length. In each line has a space. Here is a line in a file looks like:
"AAB, FFC, EEE, FEF, JKL, JJK"
"FDL, JLJ, KK


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


help: parsing html file u... Unix: File manipulation



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Find length of each line in a file.

Read first character of each Line www.computing.net/answers/unix/read-first-character-of-each-line/8088.html

finding consecutive lines in a file www.computing.net/answers/unix/finding-consecutive-lines-in-a-file/3996.html

how to replace a line in a file www.computing.net/answers/unix/how-to-replace-a-line-in-a-file/7214.html